首页 文章

在Vuex商店中使用vue-router

提问于
浏览
0

我想使用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})
    },

谢谢!

1 回答

  • 0

    答案是我不得不在商店中使用正常的 this.$router 语法,而只是这样做: router.push({name:'summary'}) . 谢谢!

相关问题