解決微信小程序 thirdScriptError錯誤

最近入坑了微信小程序,遇到了很多問題,今日份的問題是 thirdScriptError!

錯誤信息如下:

錯誤版源碼(已刪除與此錯誤無關的代碼):

Page({
  data: {
    //用於保存input的輸入內容
    words:null
  },


  //獲取input輸入框的內容
  input:function(e){
    this.setData({words:e.detail.value})
  },
 
  //點擊按鈕,在日誌中打印出輸入框的內容
  btnclick:function(){
    console.log(words)
  }
})

正確版源碼:

Page({
  data: {
    words:null
  },

  input:function(e){
    this.setData({words:e.detail.value})
  },
 
  btnclick:function(){
    //不能直接通過words訪問!!!!!!!!!
    console.log(this.data.words)
  },
})

錯誤原因:

在函數中引用變量需要this指向!!!

 

第一次補充:

我又遇到了這個錯誤,這次的原因很弱智,就是在js文件中給變量賦值的時候應該用冒號,我不小心用了等號。

錯誤:

myData: {
    username="hello"
}

正確:

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