I have very little experience working with vue js.
There are two functions that I am using: loadComponentsOfUser()
and loadUserId()
. The loadComponentsOfUser() function depends on the userID field being loaded by the loadUserId() function.
data() {
return {
userId: ''
}
},
created() {
this.loadComponentsOfUser()
},
methods(): {
loadUserId() {
axios.get('getUserId').then(res => {
this.userId = res.data
}).catch(() => {
...
})
});
},
loadComponentsOfUser() {
this.loadUserId()
axios.get('users/' + this.userId).then(res => {
}).catch(() => {
...
})
});
}
The loadUserId() function is functioning correctly in fetching the correct value from the server.
However, when loadComponentsOfUser() is called, it appears that the this.userId field has not been initialized and an empty field is passed to axios.
My main concern is why the field was not initialized after the loadUserId() call?