NProgress是一款在网页顶部添加细长进度条的工具,非常轻巧,使用起来也非常便捷,灵感来源于Google, YouTube。

 

1、安装

 

$ npm install --save nprogress 或者
$ yarn add nprogress

//用法
NProgress.start();
NProgress.done();

 

 

2、使用

router.js

 

//导入
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

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

router.afterEach(() => {
  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();
});

 

广州品牌设计公司https://www.houdianzi.com PPT模板下载大全https://redbox.wode007.com

3.vue使用NProgress 修改颜色

在App.vue中的style中增加:

 

  <style>
  #nprogress .bar {
      background: red !important; //自定义颜色
    }
</style>

相关文章:

  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
  • 2021-08-13
猜你喜欢
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
  • 2022-02-07
相关资源
相似解决方案