注意:es6箭頭函數沒有this
//注意:es6箭頭函數沒有this
bindPickerRoleChange: (e)=>{
console.log(this);//輸出undefined
//this當前爲undefined,會報錯;Cannot read property 'data' of undefined;
this.setData({
RoleValue: 3
})
}
},
//正確方法
bindPickerRoleChange: function(e) {
console.log(this);//輸出this對象
//正常賦值
this.setData({
RoleValue: 3
})
}
}