當(dāng)在mutations 里面去添加路由的時候,報錯了。剛接觸vuex 不是很清楚這里的關(guān)系,希望各位大佬能夠解答一二。什么情況下會出現(xiàn)這種問題,給予一個思路也是可以的。mutations :{ // 動態(tài)添加主界面路由,需要緩存
updateAppRouter: (state, routes) => {
state.routers.push(...routes)
router.addRoutes(routes)
}, // 動態(tài)添加全局路由,不需要緩存
updateDefaultRouter (state, routes) {
router.addRoutes(routes)
},
}
2 回答

Cats萌萌
TA貢獻(xiàn)1805條經(jīng)驗 獲得超9個贊
vuex的mutation中是看不到router對象的。。。
mutation最好只用來更新state的屬性,不用做其他。
如果要引用路由對象應(yīng)該在Vue對象中使用。

慕容3067478
TA貢獻(xiàn)1773條經(jīng)驗 獲得超3個贊
不能把這句放到外面去執(zhí)行嗎router.addRoutes(routes)
那可以試試吧router對象傳進(jìn)去
this.$store.commit('router', {path: '/', router :this.$router}); router(state, {path, router}) { router.push(path); }
添加回答
舉報
0/150
提交
取消