1👍
mounted
is synchronous. loadUsers
is doing something asynchronous, but is executing it through a synchronous function. Either turn both of them into an async
function and use await
or have loadUsers
return a promise that’s resolved inside the then
, which the mounted
function then also assigns the value to this.users
.
async method
methods: {
async loadUsers() {
let { data } = await axios.get('/karma/post-users-chart')
this.users = data.users
this.labels = data.labels
this.max = data.max
},
},
async mounted() {
await this.loadUsers();
console.log(this.users); // it returns null
}
👤A. L
- [Vuejs]-Vue.JS: Why won't parent element receive event? Does parent have to be a custom component?
- [Vuejs]-Laravel – Parse Blade to Vue Component
Source:stackexchange.com