<input type="" bindinput="handleInput"></input>
<button bindtap="handtap" data-operation="{{1}}">+</button>
<button bindtap="handtap" data-operation="{{-1}}">-</button>
<view> {{num}}</view>

 

Page({

/**
* 页面的初始数据
*/
data: {
num:0
},
// 输入框的input事件的执行逻辑
handleInput(e){
// console.log(e.detail.value);
this.setData({
num:e.detail.value
})
},
// 加 减 按钮的事件
handtap(e){
// console.log(e);
// 1 获取自定义属性 operation
const operation = e.currentTarget.dataset.operation;
this.setData({
num: parseInt(this.data.num) + operation
})
}
})