第一种情况,明明定义了一个XXX属性,却提示Cannot read property ‘XXX’ of undefined;
TypeError: Cannot read property ‘XXX’ of undefined。
第二种情况,使用this.setData报错:thirdScriptError, this.setData not a funtion。
第一种解决方法:吧普通函数
function (res) {
...
}
变成箭头函数
(res) => {
},因为箭头函数内部是有没this的绑定,函数里面的this就是函数外部的this。
第二种方法:function(res){
//在普通函数的开头添加
var _this = this;
},来绑定this