使用VUEX使用V-Skeleton-Loader的最佳实践
我想在尚未获取API的数据时进行V-Skeleton-Loder
加载。问题是我使用调度调用该动作。
getSomething(id) {
this.$store.dispatch("getSomething");
},
这是我的骨架,我还使用计算属性从VUEX中称为加载
。
<v-skeleton-loader type="table" :loading="loading"></v-skeleton-loader>
我将加载加载到我的商店中
state : {
loading:true}
actions: {
async getSomething(){
await axios.get(url)
.then(async () => {
state.loading = false //after data is fetched
})
.catch((err) => {
console.log(err)
})
}
}
。还是在不使用Vuex的情况下有其他更有效的方法来实现这一目标?感谢所有的帮助,谢谢!
I want to make v-skeleton-loder
loading when the data from API is not yet fetched. The thing is I use dispatch to call the action.
getSomething(id) {
this.$store.dispatch("getSomething");
},
Here is my skeleton, and I also called the loading
from Vuex using computed property.
<v-skeleton-loader type="table" :loading="loading"></v-skeleton-loader>
I put the loading in my store.js like this
state : {
loading:true}
actions: {
async getSomething(){
await axios.get(url)
.then(async () => {
state.loading = false //after data is fetched
})
.catch((err) => {
console.log(err)
})
}
}
This doesn't work and I also don't know how to set the loading
value back to true for other skeletons. Or is there any more efficient way to achieve this without using Vuex? Appreciate all help, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以设置VUEX状态以进行加载:
然后在之前和之后派遣操作
You can set vuex state for loading:
then dispatch action before and after
您不会直接突变状态,它是使用突变完成的。我可能在代码中犯了错误。将其用作概念。
you don't mutate state directly, it is done using mutations.I may have made mistakes in the code. Use it as a concept.