Vue加載進(jìn)度條

show

一、nprogress

路由懶加載會(huì)使得我們?cè)诘谝淮未蜷_(kāi)一個(gè)新頁(yè)面的時(shí)候,會(huì)有一個(gè)加載時(shí)間。如果在這個(gè)時(shí)候我們沒(méi)有一個(gè)提示的話,給人的感覺(jué)會(huì)是好像我點(diǎn)了頁(yè)面跳轉(zhuǎn)但是沒(méi)反應(yīng)。所以,這個(gè)時(shí)候我們可以加一個(gè)進(jìn)度條來(lái)告知用戶。
https://github.com/rstacruz/nprogress

二、配置vue項(xiàng)目

安裝

npm install --save nprogress

使用

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
//進(jìn)度條
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import App from './App'
import router from './router'

Vue.use(ElementUI);
Vue.config.productionTip = false
//進(jìn)度條
NProgress.configure({
  easing: 'ease',  // 動(dòng)畫(huà)方式
  speed: 500,  // 遞增進(jìn)度條的速度
  showSpinner: false, // 是否顯示加載ico
  trickleSpeed: 200, // 自動(dòng)遞增間隔
  minimum: 0.3 // 初始化時(shí)的最小百分比
})

router.beforeEach((to, from , next) => {
  // 每次切換頁(yè)面時(shí),調(diào)用進(jìn)度條
  NProgress.start();
  // 這個(gè)一定要加,沒(méi)有next()頁(yè)面不會(huì)跳轉(zhuǎn)的。這部分還不清楚的去翻一下官網(wǎng)就明白了
  next();
})
router.afterEach(() => {
  // 在即將進(jìn)入新的頁(yè)面組件前,關(guān)閉掉進(jìn)度條
  NProgress.done()
})

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

全局定義顏色

image.png
  /*進(jìn)度條顏色*/
  #nprogress .bar {
    background: blue !important;
  }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容