在应用开始之前更新一段数据?

pan*_*hro 0 vue.js vuejs2

我需要在应用程序"启动"之前编辑一段我的数据,在阅读内容后,我可以在创建中执行此操作,但它出现错误:

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)

mau*_*ceg 5

这是范围问题(绑定this)

尝试定义这样的created方法:

created () {
  console.log(this.test) //should log hello
}
Run Code Online (Sandbox Code Playgroud)

有关完整示例,请参阅我创建的这个JSFiddle:https://jsfiddle.net/u96L1maz/1/