記:微信小程序開發中踩到的坑

注意: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
      })
    }
 }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章