javascript - 仅在 NProgress.done() 之后如何在 Vue 组件中显示元素
问题描述
为了在 VueJS 应用程序中显示加载状态,我使用了 library NProgress
。它运行良好,并显示了加载条和纺车。然而,页面的 HTML 内容已经被渲染和显示。我想在请求运行时隐藏页面的某些部分。
NProgress.done()
调用后是否有可能以编程方式检查并显示内容?
我想要这样的东西:
<template>
<div>
<NavBar />
<div v-show="check here for NProgress.done()">
<p>Here are all the nice things with placeholders for the data from the API.</p>
</div>
</div>
</template>
<script>
import NavBar from '@/components/NavBar';
export default {
components: {
NavBar
}
}
</script>
“在此处检查 NProgress.done()”部分是我不知道如何解决的。
解决方案
查看 NProgress 的文档,它看起来像公开了一个“.status”,它返回当前加载程序的值,但在加载程序未“启动”时返回一个“null”。
<template>
<div>
<div v-show="state.status == null">
<p>
Here are all the nice things with placeholders for the data from the
API.
</p>
</div>
</div>
</template>
<script>
import Vue from "vue";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
const state = Vue.observable(NProgress);
export default {
data: () => ({ state }),
mounted: function () {
NProgress.start(); // Start the bar loading
setTimeout(() => { // Perform your async workloads
NProgress.done(); // .done() to finish the loading
}, 5000);
},
};
</script>
你需要让 NProgress 反应,所以你可以只使用 Vue.observable(state)。
推荐阅读
- swift - Swift 协议初始化程序排除了向 struct 添加更多存储属性
- php - 如何从 api 响应中获取特定的字符串?
- python - 如何在tensorflow中将字典转换为张量
- c++ - 可以在 Win32 中对对话框进行超类化吗?
- assembly - 如何使用 cmp 比较两个文字
- python - 我只是想在 GUI 中显示图像。我究竟做错了什么?
- java - 使用 Endless RecyclerView 作为日历
- python - Regex: Split characters with "/"
- php - 如何将php中的选定数据从flutter排序到mysql
- mysql - 如何在mysql和nodejs连接中使用sockepath