一, 安装
npm i vue-ins-progress-bar
二, main.js
import VueInsProgressBar from 'vue-ins-progress-bar' const options = { position: 'fixed', show: true, height: '3px' } Vue.use(VueInsProgressBar, options)
三, App.vue
<template> <div id="app"> <router-view/> <vue-ins-progress-bar></vue-ins-progress-bar> </div> </template> <script> export default { name: 'App', mounted () { this.$insProgress.finish() }, created () { this.$insProgress.start() this.$router.beforeEach((to, from, next) => { this.$insProgress.start() next() }) this.$router.afterEach((to, from) => { this.$insProgress.finish() }) } } </script>
四, APIs
this.$insProgress.start() // 开始回调
this.$insProgress.finish() // 结束回调
this.$insProgress.height(4) //
加载栏的高度调整为4px
Dome