在vue项目中使用Nprogress.js进度条

    xiaoxiao2021-04-17  41

    Ajaxyy应用程序的细长进度条。灵感来自Google,YouTube和Medium。

    在vue中使用nprogress.js

    安装

    $ bower install --save nprogress $ npm install --save nprogress

    在项目中引入

    在main.js中引入要使用的nprogress

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

    基本用法

    NProgress.start(); 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://ju.6miu.com/read-673699.html

    最新回复(0)