How do I wait / await for a slow-ish api call to finish and commit to store before doing something with the store object?
For example, in created() in App.js I do the below and if I don't wrap my transform functions in a timeout the data isn't committed yet and so they fail.
App.js
created: function () {
this.$store.dispatch("loadData"); // loads all the data and commits to store as state.eventsData
setTimeout(() => { // if I don't wrap these in a timeout, this.eventsData is not available for the functions
this.transformDataForGrid(); // transforms eventsData and commits it as gridData
this.transformDataForCalendar(); // transforms eventsData and commits it as calendarData
}, 500);
},
methods: {
transformDataForGrid(){// lots of manipulations of eventsData then state.commit("gridData", newdata},
transformDataForCalendar(){},// lots of manipulations of eventsData then state.commit("calendarData", newdata},
}