vue 路由跳转进度条 Nprogress.js

安装Nprogress

npm install nprogress -S

在main.js中引入Nprogress

import NProgress from 'nprogress';
import 'nprogress/nprogress.css';

路由拦截器里使用Nprogress

注意在router.beforeEach里一定要加上next()否则路由不会跳转

router.beforeEach((to, from, next) => {
  NProgress.start();
  next()
});

router.afterEach(transition => {
  NProgress.done();
});

main.js文件最后如下

import Vue from 'vue'
import App from './App'
import router from './router'
import Mixin from './mixins';
import filters from './filters';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
Vue.mixin(Mixin);

Vue.config.productionTip = false
Object.keys(filters).forEach(k => Vue.filter(k, filters[k]));

router.beforeEach((to, from, next) => {
  NProgress.start();
  next()
});

router.afterEach(transition => {
  NProgress.done();
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

猜你喜欢

转载自blog.csdn.net/qq_35285627/article/details/80811056
今日推荐