小程序的方法如何获取view上的数据
在小程序里,view使用data-XX(XX是自定义的名称)绑定数据,在方法里可以通过event.currentTarget.dataset.XX获取这个数据
<view data-spu-id="{{item.id}}" bind:tap="onTap" class="spu-container">
</view>
js
methods: {
onTap(event) {
console.log(event)
const spuId = event.currentTarget.dataset.spuId
console.log(spuId)
}
}