TypeError: Cannot read property 'setData' of undefined 错误通常发生在尝试访问一个未定义(undefined)对象的 setData 方法时。在小程序中,这通常是由于在回调函数中 this 的指向发生了变化,不再指向页面实例。 3. 检查代码逻辑 审查相关代码,特别是涉及 setData 调用的部分。确保在调用 setData 之前,对象已被正确...
如果这么写,会遇到“Cannot read property 'data' of undefined ”的错误。、 箭头函数是ES6的写法,不同的写法,会导致“this”的指代层级不同,所以会找不到data属性。 代码语言:javascript 复制 wx.showModal({title:'提示',content:'这是一个弹窗',success:(res)=>{if(res.confirm){this.data.messageId}els...
success (res) {if(res.confirm) {this.data.messageId }elseif(res.cancel) { console.log('用户点击取消') } } }) 如果这么写,会遇到“Cannot read property 'data' of undefined ”的错误。 如果改成箭头函数的写法,就不会出错。 wx.showModal({ title:'提示', content:'这是一个模态弹窗', succes...
我们只用在OntitleClick事件里面加上var that = this;就行了 因为在调用 OntitleClick() 之前就已经把 this 复制了一份保存在 that 变量中,你复制的这个this是指向的page中data,那你相当于用这行代码搭了个桥,让that.setData指向了Page中的data 2.用箭头函数一样好使 这样和上面是一样的,我在慕课上面看到有...
微信小程序 --- 【TypeError: Cannot read property ‘forceUpdate‘ of undefined】 1. 报错 2. 报错原因 由于使用的是 Taro 多端框架,运行编译后的微信小程序没有对应的AppId导致! 3. 解决办法 设置---> 项目设置 ---> 基本信息 ---> 在APPID栏目添加你自己申请的appid,或者使用测试的appid 4. ...
this.data.messageId } else if (res.cancel) { console.log('用户点击取消') } } }) 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 如果这么写,会遇到“Cannot read property ‘data’ of undefined ”的错误。 如果将success改成箭头函数的写法,就不会出错。
解决办法: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("重新刷新数据");})}})}...
简介:【微信小程序】TypeError: Cannot read property ‘get‘ of undefined & Error: MiniProgramError 一、问题场景 在写 uni-app 项目的时候,跟着视频一步一步的弄,一运行就发现报错了,然后就开始各种百度了。 找不到定义 WAServiceMainContext.js?t=wechat&s=1680006165208&v=2.30.2:1 TypeError: Can...
这是因为当前小程序项目没有设置 appid 导致的,使用的是默认值 touristappid。 三、解决办法 设置appid ,如果你已申请了小程序,那么直接进入小程序后台,拿到 appid 即可;如果你还没有申请小程序,那么使用测试 appid 即可,两种方式都可以解决上面的报错。拿到 appid 之后,找到项目中的 manifest.json 文件, 选择 【...
【微信小程序】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