再使用導(dǎo)航守衛(wèi)時候,需要判斷vuex中的內(nèi)容,但是沒有this,偶然發(fā)現(xiàn)可以使用router這個對象獲取到
import Vue from 'vue'
import VueRouter from 'vue-router'
import Map from '@/components/Map'
import Service from '@/components/Service'
import Confirm from '@/components/Confirm'
Vue.use(VueRouter)
//定義路由
let routes = [
{path: '/map', component: Map},
{path: '/service', component: Service},
{path: '/confirm', component: Confirm},
{path: '/', component: Map},
]
//創(chuàng)建路由實例
let router = new VueRouter({
mode: 'history',
routes,
})
router.beforeEach((to, from, next) => {
//這個router包含了大部分的內(nèi)容
console.log(router.app.$store.getters.user)
next()
})
export default router;