1.安装
$ npm install --save nprogress
$ yarn add nprogress
2.使用
App.vue
<script lang="ts">
import NProgress from "nprogress";
import "nprogress/nprogress.css";
import { useRouter } from "vue-router";
export default {
setup() {
const router = useRouter();
router.beforeEach((to, from, next) => {
NProgress.start();
next();
});
router.afterEach(() => {
NProgress.done();
});
},
};
</script>
Ts报错解决
import NProgress from "nprogress";
shims-vue.d.ts
declare module 'nprogress';