标签:微信 data console 函数定义 ref develop nload api style
先说原因:
这么写会报错
thirdScriptError
this.setData is not a function;at pages/index/index onLoad function;at api getSystemInfo success callback function
TypeError: this.setData is not a function
onLoad: function () { wx.getSystemInfo({ success: function (res) { this.setData({ lang: res.language }) console.log(res.language) } })
这么改一下就不报错了。
1 onLoad: function () { 2 wx.getSystemInfo({ 3 success: (res) => { 4 this.setData({ 箭头函数的this始终指向函数定义时的this 5 lang: res.language 6 7 }) 8 console.log(res.language) 9 } 10 })
或者这样:
onLoad: function () { var that=this; wx.getSystemInfo({ success: function (res) { that.setData({ lang: res.language }) console.log(res.language) } })
标签:微信 data console 函数定义 ref develop nload api style
原文地址:https://www.cnblogs.com/jjkv3/p/11371609.html