如何检查我的 api 请求是否从fetchData
函数返回任何数据?,我想返回boolean
(或其他东西)到我的Index.vue
并在加载数据时显示加载器但是当数据加载时我想使用:this.$router.push("admin/dashboard")
重定向到另一个页面显示此数据,
我的代码:
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
})
})
}
谢谢你的帮助