就比如说我在小程序里写了一个公共的弹层,点击其中一个弹层会显示对应的内容
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的情况就不能使用箭头函数?
安静的沙漠
Geek丶
若小点
考拉2
随时随地看视频慕课网APP