在线
客服

发布
需求

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

微信小程序中setData的问题

就比如说我在小程序里写了一个公共的弹层,点击其中一个弹层会显示对应的内容
js部分如下
layerTap(e){    this.setData({      index: this.data.expert[e.currentTarget.dataset.index],      expertDetail: true//显示弹层    })}如果我用箭头函数,就会报【Cannot read property 'setData' of undefined;at "page/discover/discover" page bindViewTap function
TypeError: Cannot read property 'setData' of undefined】代码如下
layerTap:(e)=>{    this.setData({      index: this.data.expert[e.currentTarget.dataset.index],      expertDetail: true//显示弹层    })}然而我在onLoad里var that = this然后再setData,依旧会报错【
that is not defined;at "page/discover/discover" page bindViewTap function
ReferenceError: that is not defined


为什么,还是说我只要遇到需要使用setData的情况就不能使用箭头函数?

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与3

十分感谢,找了好久的BUG,箭头函数不能操作Page的data,

使用道具 举报

不应该在onload里面声明var that = this; 因为onload本身就是一个作用域! 应该在你写的函数里吗 声明

使用道具 举报

...

使用道具 举报

发新帖
国内首家创新型IT技术需求众包服务平台,软件需求就上天盟网! 立即登录 立即注册