Answer the question
In order to leave comments, you need to log in
How to asynchronously fetch data in the "created" hook?
Hello everyone, please tell me how to get the data correctly?
Let's go in order, This is a function in methods iterates over my array for a match in Json,
Also in methods and Axios request, but I call it in created ( see below )
toggleIcon: function() {
for(var key in this.icon) {
if (this.icon[key].id.slice(0,2) == this.value_icon) {
this.icon[key].value = true ;
}
}
}
created() {
this.getPosition();
this.measureSystemC();
this.measureSystemF();
this.toggleIcon(); // no access to variable with json
},
Answer the question
In order to leave comments, you need to log in
Created supports async. You can add code like this (await can be specified, only for a method with a promise)
async created() {
await this.getPosition();
await this.measureSystemC();
await this.measureSystemF();
this.toggleIcon();
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question