我需要在应用程序"启动"之前编辑一段我的数据,在阅读此内容后,我可以在创建中执行此操作,但它出现错误:
Cannot read property 'test' of undefined
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
data() {
return {
test: 'hello',
}
},
created:() => {
console.log(this.test); //should log hello
}
Run Code Online (Sandbox Code Playgroud)
这是范围问题(绑定this)
尝试定义这样的created方法:
created () {
console.log(this.test) //should log hello
}
Run Code Online (Sandbox Code Playgroud)
有关完整示例,请参阅我创建的这个JSFiddle:https://jsfiddle.net/u96L1maz/1/
| 归档时间: |
|
| 查看次数: |
38 次 |
| 最近记录: |