Use the Nprogress. js progress bar method in the vue project, vuenprogress. js

Source: Internet
Author: User
Tags sessionstorage

Use the Nprogress. js progress bar method in the vue project, vuenprogress. js

NProgress. js provides the page loading progress bar effect. When the page is opened for loading, the progress bar loading animation will appear at the top of the page. NProgress. js is a lightweight progress bar component that is easy to use and can be easily integrated into single-page applications.

The long progress bar of the Ajaxyy application. Inspired by Google, YouTube, and Medium.

Use nprogress. js in vue

Install

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

Introduce

Introduce the nprogress to be used in main. js

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

Basic usage

NProgress.start(); NProgress.done();

Use on the routing page

In 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();});

Summary

The above section describes how to use Nprogress In the vue project. js progress bar method, hope to help you, if you have any questions, please leave a message, xiaobian will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.