vue配置nprogress實現(xiàn)頁面頂部進度條
更新時間:2019年09月21日 14:48:12 作者:人間草木96
這篇文章主要為大家詳細介紹了vue配置nprogress實現(xiàn)頁面頂部進度條,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue配置nprogress實現(xiàn)頁面頂部進度條的具體代碼,供大家參考,具體內(nèi)容如下
1. 安裝
npm install nprogress --save
2. 在main.js中導(dǎo)入
源碼~~~~~~方便你復(fù)制
// 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 App from './App' import router from './router' import iView from 'iview' import 'iview/dist/styles/iview.css' import moment from './plugins/moment' import axios from './plugins/axios' import NProgress from 'nprogress' import 'nprogress/nprogress.css' import { base } from './router/config' Vue.use(iView) Vue.use(moment) Vue.use(axios) Vue.config.productionTip = false // 配置NProgress進度條選項 —— 動畫效果 NProgress.configure({ ease: 'ease', speed: 500 }) // 全局路由攔截-進入頁面前執(zhí)行 router.beforeEach((to, from, next) => { if (to.path === `${base}login`) { return next() } // token驗證,如果存儲在sessionStorage里的auth的值丟失,就回到登陸頁面,(開發(fā)時可以注釋掉) // if (!sessionStorage.getItem('auth')) { // return next(`${base}login`) // } // 如果頁面在 / 默認頁面,跳轉(zhuǎn)到登陸頁面(和vue路由重定向功能類似) if (to.path === `${base}`) { return next(`${base}login`) } // NProgress開始進度條 NProgress.start() next() }) // 全局后置鉤子-常用于結(jié)束動畫等 router.afterEach(transition => { // NProgress結(jié)束進度條 NProgress.done() // console.log(transition) }) /* eslint-disable no-new */ new Vue({ el: '#app', router, components: { App }, template: '<App/>' })
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue實現(xiàn)數(shù)據(jù)篩選與搜索功能的示例代碼
在許多Web應(yīng)用程序中,數(shù)據(jù)篩選和搜索是關(guān)鍵的用戶體驗功能,本文將深入探討在Vue中如何進行數(shù)據(jù)篩選與搜索的實現(xiàn),感興趣的小伙伴可以跟隨小編一起學(xué)習一下2023-10-10vue給input file綁定函數(shù)獲取當前上傳的對象完美實現(xiàn)方法
這篇文章主要介紹了vue給input file綁定函數(shù)獲取當前上傳的對象完美實現(xiàn)方法,需要的朋友可以參考下2017-12-12