vue-navigation-progress-plugin
v1.0.2
Published
vue-router plugin
Downloads
28
Maintainers
Readme
支持vue-router + webpack2 代码分割的路由进度显示
Important
- 如果使用代码分割,异步组件加载需使用
Webpack2
的System.import()
Installation
- via CDN
<script src="https://unpkg.com/vue-navigation-progress-plugin/dist/vue-navigation-progress-plugin.min.js"></script>
simple example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<script src="https://unpkg.com/vue-navigation-progress-plugin/dist/vue-navigation-progress-plugin.min.js"></script>
</head>
<body>
<div id="app">
<!-- 放置进度条组件 -->
<router-progress></router-progress>
<router-view></router-view>
</div>
<template id="index">
<div>
<h1>this is index page</h1>
<router-link to="/list">go to list</router-link>
</div>
</template>
<template id="list">
<div>
<h1>this is list page</h1>
<router-link to="/">go to index</router-link>
</div>
</template>
<script>
Vue.use(VueRouter);
var router = new VueRouter({
routes: [{
path: "/",
component: { template: "#index" },
meta: { title: "首页" }
}, {
path: "/list",
component: { template: "#list" },
meta: { title: "列表页" }
}]
});
Vue.use(vueNavigationProgressPlugin, router);
new Vue({
el: "#app",
router
})
</script>
</body>
</html>
- via NPM
$ npm install vue-navigation-progress-plugin --save # Or
$ yarn add vue-navigation-progress-plugin
simple example
// main.js
import Vue from "vue";
import VueRouter from "vue-router";
import App from "./App";
import vueNavigationProgressPlugin from "vue-navigation-progress-plugin";
Vue.use(VueRouter);
const router = new VueRouter({
routes: [{
path: "/",
component: () => System.import("components/index.vue") // 注意 必须使用System.import
},{
path: "/list",
component: () => System.import("components/list.vue")
}]
});
Vue.use(vueNavigationProgressPlugin, router);
new Vue({
el: "#app",
router,
render: h => h(App)
});
<!-- like App.vue -->
<template>
<div id="app">
<!-- 放置进度条组件 -->
<router-progress/>
<router-view/>
</div>
</template>