Using Vue, I want to implement async/await to sequence my functions A and B.
Result is set to false by default.
mounted() {
this.A();
this.B();
}
async A() {
this.result = await this.$api...
}
async B() {
if(this.result) {
let data = await this.$another1 api...
} else {
let data = await this.$another2 api...
}
}
I expect that after function A calls the API and returns a value for 'result,' function B will execute its job.
Sometimes, however, the API in function B calls 'another2 api' before 'this.result' gets its value even if the result is 'true' after function A receives a value from $api.
https://i.sstatic.net/3nIF3.png
This is the normal behavior I anticipate.
https://i.sstatic.net/6RLg3.png
This error occurs occasionally when I refresh the page.
How can I resolve this issue?