微信小程序:setData报错TypeError: Cannot read property ‘setData‘ of undefined,问题的原因:无法找到setData这个定义,因为setData中是onLoad函数中的方法中的子节点,无法使用this解决办法:这个时候需要在方法的开始部分定义varthat=this,然后用that.setData来重
无法找到setData这个定义,因为setData中是onLoad函数中的方法中的子节点, 无法使用this 解决办法: 这个时候需要在方法的开始部分定义var that = this,然后用that.setData来重置,这样就解决了这个问题了。 如下图: 本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2021/07/22 ,如有侵权请联系...
解决办法:loginAct: () => {}改成loginAct(){} loginAct(){console.log("执行了");varthat=this;wx.getStorage({key:'user',success:function(res){console.log("信息数据res为",res);that.setData({userInfo:res.data,},()=>{console.log("重新刷新数据");})}})}...
今天写小程序,需要读取窗口高度然后设置scroll-view高度,在this.setData时报错“Cannot read property 'setData' of undefined”,代码如下: onShow: function () { wx.getSystemInfo({ success: function(res) { this.setData({ scrollHeight:res.windowHeight-100*res.windowHeight/750 }); }, }); }, 原因是g...
进入正题吧,刚在写代码的时候,报了这样一个错误 然后把this输一下是undefined,因为这个时候this指向的是当前wx对象,而wx对象没有setData,我们应该将this的指向修改为page对象 只要把success改成箭头函数就ok啦。。。
【微信小程序】TypeError: Cannot read property 'setData' of undefined,解决方案 https://www.jianshu.com/p/4f7b33e3e1df 对比分析success:(res)=>{console.log("(res)=>{}时:"+this);},---success:function(res){console.log("fun
wx.login({ success: res => { this.setDate({res:res}) } });比如上面的代码,回报'setData' of undefined, 这是因为这里的this已经不是原来的this了,这个时候我们一般这样用 let _this = this; wx.l…
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 bind...
this.setData({num: '0.'})this.isClear = false return } // if (this.data.num.indexof('....
this.setData({ n: ev.currentTarget.dataset.index }) } 3. 根据 sitemap 的规则[0],当前页面 [pages/class/class] 将被索引 在小程序项目配置文件 project.config.json 的 setting 中加入 "checkSiteMap": false, 4. the server responded with a status of 500 [外链图片转...