[Vuejs]-Updating a piece of data before app starts?

5👍

It’s an issue of scope (binding of this)

Try defining the created method like this:

created () {
  console.log(this.test) //should log hello
}

For full example see this JSFiddle I created: https://jsfiddle.net/u96L1maz/1/

0👍

In addition to the other solutions, this also will work.

new Vue({
  el: '#app',
  data: () => {
    return {
      hello: 'hello',
      bye: 'bye'
    }
  },
  created: () => {
    console.log(hello) // hello
    console.log(bye) // bye
  }
})

Leave a comment