平时做web网页开发的时候都是通过在onclick中添加函数名和参数实现的。
<button type="button" onclick="delete(1)">
但是仿照这种做法,在微信小程序中的bindtap中指明函数名和参数后
<button type="button" bindtap="delete(1)">
控制台就会报 Do not have delete(1) handler in current page的错误。
原因是在微信小程序中只需在bindtap中指明函数名即可。
参数通过在标签上添加data-加参数名的属性来指明,比如上一个列子,我们在微信小程序中应该
<button type="button" bindtap="delete" data-id="1">
在js文件中添加
active: function(e){
var id = e.currentTarget.dataset.id;
console.log(id);
}
同样添加多个参数也是可以的
试试吧~