最近入坑了微信小程序,遇到了很多问题,今日份的问题是 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"
}
错误原因:
....... 不准粗心了啊!!