npm install --save nprogress在项目中引入 在main.js中引入要使用的nprogress
import NProgress from 'nprogress' import 'nprogress/nprogress.css'基本使用
NProgress.start(); NProgress.done();代码 (同样在main.js中)
router.beforeEach((to, from, next) => { if (to.path == '/login') { sessionStorage.removeItem('username'); } let user = sessionStorage.getItem('username'); if (!user && to.path != '/login') { next({path: '/login'}) } else { NProgress.start(); next() } }); router.afterEach(transition => { NProgress.done(); })