How to check if my api request returns me any data from fetchData function?, I want to return boolean(or something else) to my Index.vue and show loader when data is loading but when data is loaded then i want to use: this.$router.push("admin/dashboard") to redirect to another page where this data is displayed,
my code:
const actions = {
fetchData({ commit },{ id}) {
return axios.get(`someUrl?hd=${id}`)
.then(response => {
if(response.status == 200) {
commit('setData', response.data),
}
})
.catch(
error => {
console.log(error);
}
);
}
}
Index.vue
<div v-if="isDataLoaded" class="loading-div">
<vue-spinner />
</div>
methods: {
...mapActions(["fetchData"]),
launchFetchData() {
new Promise(() => {
this.$store.dispatch("fetchData", {
id: this.id
})
})
}
thanks for any help