How to change the variable in the data from a mounted in the promise?

Hello, tell me why the hook is mounted or created from promise->then you can't change a variable in the data, example:

data(){
 return {
 foo: null
}
},
created(){
 this.foo = "baR"
 this.$http.get("server.api").then( () => {
 this.foo = "baZ" 
})
 console.log(this.foo) // -> "baR"
}

Even if you bandit context, the result is the same
March 23rd 20 at 19:02
0 answer

Find more questions by tags Vue.js