下载
npm i nprogress
在main.js中引入:
import App from './App' import VueRouter from 'vue-router' import router from './router' //你的路由文件 //引入nprogress import NProgress from 'nprogress' import 'nprogress/nprogress.css' //这个样式必须引入 Vue.use(VueRouter) // 简单配置 NProgress.inc(0.2) NProgress.configure({ easing: 'ease', speed: 500, showSpinner: false }) router.beforeEach((to,from,next) => { NProgress.start() next() }) router.afterEach(() => { NProgress.done() }) new Vue({ el: '#app', router, render: h => h(App) })
进度条颜色修改:
在vue文件中修改,建议App.vue中 #nprogress .bar { background: red !important; //自定义颜色 }