1.微信小程序的事件绑定就是bind+你想要绑定的事件
<input type="text" bindinput="handleInput"/>
handleInput(e){
console.log(e.detail.value); this.setData({ num:e.detail.value }) }
要获取输入框中的值,e.detail.value
如果要把输入框中的值赋值给其他地方,不能像以前一样采用this.data=e.detail.value的方式,要使用this.setData
2.小程序中不能直接在事件中传参,要使用自定义属性,data+要传的值
<button bindtap="handletap" data-operation="{{1}}">+</button><button bindtap="handletap" data-operation="{{-1}}">-</button>
<view >{{num}}</view>
handletap(e){ console.log(e); const operation=e.currentTarget.dataset.operation this.setData({ num:(this.data.num+operation)*1 // num:this.data.num+operation }) }
自定义属性中定义的operation的值,在handletap中获取到,定义一个operation接受,利用赋值操作更新num的值,就实现了点击按钮加减操作
乘1是因为转换成number,进行隐式转换,也可以使用Number()