Answer the question
In order to leave comments, you need to log in
How to correctly add data to initial state Vue.data from axios response?
I set the initial state of the data to the root Vue instance
data:function(){ return {
Config: {},
list: [],
activeService: ''
}},
created: function(){
axios.get("/jsondata/stepdata/step-1.json")
.then(function(response){
rootVueSteplist.$data = response.data;
})
}
created: function(){
axios.get("/jsondata/stepdata/step-1.json")
.then(function(response){
rootVueSteplist.$data = Object.assign(rootVueSteplist.$data, response.data)
})
}
created: function(){
axios.get("/jsondata/stepdata/step-1.json")
.then(function(response){
rootVueSteplist.$data.Config = response.data.Config;
rootVueSteplist.$data.list = response.data.list;
})
}
created: function(){
axios.get("/jsondata/stepdata/step-1.json")
.then(function(response){
rootVueSteplist.$set(rootVueSteplist.$data, response.data)
// rootVueSteplist.$data = Object.assign(rootVueSteplist.$data, response.data)
})
Answer the question
In order to leave comments, you need to log in
rootVueSteplist.$data = Object.assign(rootVueSteplist.$data, response.data)
Object.assign(rootVueSteplist.$data, response.data)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question