【发布时间】:2021-04-16 18:02:17
【问题描述】:
如何检查我的 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
})
})
}
感谢您的帮助
【问题讨论】:
标签: javascript css reactjs typescript vue.js