【发布时间】:2017-12-18 19:46:57
【问题描述】:
我想使用 vue-router 从 Vuex 商店路由到新组件。是否可以从 Vuex 商店访问路由器?我已经看到了一堆关于它的线程,但没有什么对我真正有用...下面的错误是我尝试使用路由器时得到的。
[Vue 警告]:挂载钩子错误:“TypeError: WEBPACK_IMPORTED_MODULE_2_vue_router.a.push 不是函数”
这是我的商店:
SENTENCE_TRACKER({commit, state}){
let chosenSentence
if(state.currSent < state.res.length) {
chosenSentence = state.res[state.currSent];
console.log(chosenSentence);
commit('CHINESE', {chineseData:chosenSentence.chinese})
commit('ENGLISH', {englishData:chosenSentence.english})
commit('PINYIN', {pinyinData:chosenSentence.pinyin})
commit('AUDIO', {audioData:chosenSentence.audio})
commit('WBW', {wbwData:chosenSentence.wbw})
state.currSent++
} else {
// THIS IS WHERE I'D LIKE TO USE VUE-ROUTER
router.push({path:'/summary'})
}
let arr = []
state.wbw.map(function(i){
arr.push('')
})
commit('WBW_STATE', {wbwStateData: arr})
let shuffled = state.wbw.slice(), i, j, k;
for (i = shuffled.length; i; i--) {
j = Math.floor(Math.random() * i);
k = shuffled[i - 1];
shuffled[i - 1] = shuffled[j];
shuffled[j] = k;
}
commit('SHUFFLED', {shuffledData: shuffled})
},
谢谢!
【问题讨论】:
-
你能显示设置
router的代码吗?
标签: vue.js vuejs2 vue-router vuex