V
V
Vyacheslav2019-06-04 13:53:43
Vue.js
Vyacheslav, 2019-06-04 13:53:43

How to change variable in data from mounted to promise?

Hello, tell me why in the mounted or created hook from promise->then it is not possible to change the variable in 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 bind the context, the result is the same

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question