1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| import vueRouter from 'vue-router' import {mapState} from 'vuex' import {mapGetters} from 'vuex' import {mapActions} from 'vuex'
const Foo = resolve => { require.ensure(['../components/Foo.vue'], () => { resolve(require('../components/Foo.vue')) }) }; const Bar = resolve => { require.ensure(['../components/Bar.vue'], () => { resolve(require('../components/Bar.vue')) }) }; const User = { template: `<section> <h3> is </h3> <div @click="increment">User:</div> <router-view></router-view> </section>`, computed: mapGetters([ 'evenOrOdd' ]), methods: mapActions([ 'increment' ]) } const Profile = { template: '<div @click="increment">profiles,and num is </div>', methods: mapActions([ 'increment' ]) } const UserPosts = {template: '<div @click="alertCount">posts</div>', methods:mapActions([ 'alertCount' ]) } const UserHome = {template: '<div>homePage</div>'}
const router = new vueRouter({ mode: 'hash', routes:[ {path: '/foo', component: Foo}, {path: '/bar', component: Bar}, { path: '/multi', components: { default: Foo, r2: Bar } }, { path: '/user/:name', component: User, name: 'user', children: [ { path: '', component: UserHome, beforeEnter: (to, from, next) => { console.log('enter user homepage'); next() } }, { path: 'profile', component: Profile, beforeEnter: (to, from, next) => { console.log('enter user profile'); next() } }, {path: 'posts', component: UserPosts}, {path: 'post',redirect: 'posts'} ] }, ], linkActiveClass: 'current' }); export default router
|