【发布时间】:2021-07-24 08:41:08
【问题描述】:
我是初学者。
我应该在 api 检索数据之前显示一个骨架。我该怎么办?
谢谢
我的解决方案是设置超时
【问题讨论】:
标签: javascript vue.js
我是初学者。
我应该在 api 检索数据之前显示一个骨架。我该怎么办?
谢谢
我的解决方案是设置超时
【问题讨论】:
标签: javascript vue.js
让我们用 Promise 完成工作:
mounted() {
// Show the skeleton before fetching
this.skeleton = true;
axios.get('url')
.then(response =>
{
this.array = response.data;
})
.catch(error => {
// do something when error occurs
})
.finally(() => {
// hide the skeleton in finally block is better than using setTimeout
this.skeleton = false;
});
}
【讨论】: