在vue中,对绑定的事件传递参数非常简单
<x-button type="primary" @click.native="changPhone(num)">确认修改绑定手机</x-button>
changPhone(num) {console.log(num)}
但是在小程序中
<view class="filter-tags" bindtap="changPhone(num)" ></view>
changPhone(num) {console.log(num)}
将会报错,原因是小程序事件不支持传递参数
解决方法,将参数绑定在元素上,通过currentTarget.dataset获取属性值
<view class="filter-tags" bindtap="changPhone" data-num={{num}}></view>
changPhone(num) {console.log(e.currentTarget.dataset.num)}