2017-07-13 11 views
0

私はVuexストアから新しいコンポーネントにルーティングするためにvue-routerを使用します。 Vuexストアからルータにアクセスすることは可能ですか?私はそれについての糸の束を見ましたが、実際に私のために働いたものは何もありません...以下のエラーは、私がルータを使用しようとするときに得られるものです。Vuexストアでvue-routerを使用する

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}) 
    }, 

ありがとう:

[Vue warn]: Error in mounted hook: "TypeError: WEBPACK_IMPORTED_MODULE_2_vue_router.a.push is not a function"

は、ここに私の店です!

+0

あなたの 'router'を設定するコードを表示できますか? –

答えて

0

答えは、通常のthis.$router構文を店舗で使用せず、代わりにこれを実行することです:router.push({name:'summary'})。ありがとう!

関連する問題