微信小程序data-绑定数据的坑来源:网络文章列表2020-06-098 在whtml中这么写
<view bindtap='like' data-id='{{laugh.id}}' data-createdBy='{{laugh.created_by}}'>
在js中取值
like(e){
console.log(e.currentTarget.dataset['createdBy']);
}
控制台输出undefined,找了半天原因, 在whtml中这么写 <view bindtap='like' data-id='{{laugh.id}}' data-createdBy='{{laugh.created_by}}'> 在js中取值 like(e){ console.log(e.currentTarget.dataset['createdBy']);} 控制台输出undefined,找了半天原因,后来网上查询了类似相同问题下才知道
原来小程序自动转了,会把下划线转为大写,大写转为小写(坑爹啊。。) like(e){ console.log(e.currentTarget.dataset['createdBy']);} 改成这样就可以了。 版权声明本站部分原创文章,部分文章整理自网络。如有转载的文章侵犯了您的版权,请联系站长删除处理。 |
|