2020年7月21日

微信小程序切图之绑定事件带参数


微信小程序切图之绑定事件带参数

1.index.wxml


<!--index.wxml-->
<view class="container">
<view id="textMessage" class="usermotto">
<!--data-user-name,data-不支持大写,但可以用驼峰代替大写-->
<text data-userid="123456" data-user-name="parry" class="user-motto" id="user-{{userId}}" bindtap="tapMessage">{{motto}}</text>
</view>
</view>

2.index.js


//index.js
//获取应用实例
const app = getApp()
Page({
data: {
motto: 'Hello World',
userId: '123',
},
onLoad: function() {},
onShow: function() {
// app.globalData.userInfo="wxopen.club";
},
tapMessage: function(event){
console.log(event);
console.log("data-userid:" + event.currentTarget.dataset.userid);
console.log("data-user-name:" + event.currentTarget.dataset.userName);
}
})

微信扫一扫二维码访问


16年前端经验
加微信好友直接沟通
了解《我的前十年》