1、安装
$ npm install nprogress --save
$ yarn add nprogress
NProgress.start();
NProgress.done();
2、使用
main.js
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
NProgress.inc(0.2)
NProgress.configure({ easing: "ease", speed: 500, showSpinner: false })
router.js
router.beforeEach((to, from, next) => {
NProgress.start();
});
router.afterEach(() => {
NProgress.done();
})
axios.js
axios.interceptors.request.use(config => {
NProgress.start();
})
axios.interceptors.respone.use(response => {
NProgress.done();
})
自定义颜色
#nprogress .bar {
height: 3px !important;
background: #56a9ff !important; //自定义颜色
}