主题
事件处理
事件绑定
有两种写法:
bind:事件名bind事件名
html
<button bind:tap="handleTap">Tap</button>
<button bindtap="handleTap">Tap</button>
<!-- 通过 data-* 传递参数 -->
<button bindtap="handleTap2" data-id="1001" data-name="Tom">Tap</button>js
Page({
handleTap(e) {
console.log(e)
},
handleTap2(e) {
// 在事件对象里通过 e.currentTarget.dataset 获取
const { id, name } = e.currentTarget.dataset
console.log(id, name)
},
})