2017-08-01 142 views
0

我在/entries/12路由上。在用戶點擊下一個按鈕時,我想在同一個組件上按/entries/13vue-router與不同參數相同的路由

代碼如下:

//e is the next page number. 
this.$router.push({ name: 'Entries', params: { pageNum: e }}); 

我得到以下錯誤:

enter image description here

,如果我嘗試的作品不同的路線。

整個代碼:

<template> 


    <div class="entries"> 

     <generic-entries @clicked="clicked" ></generic-entries> 

    </div> 

</template> 

<script> 
    import GenericEntriesComp from '@/components/GenericEntriesComp'; 

    export default{ 
     name: 'entries-comp', 

     components: {genericEntries: GenericEntriesComp}, 
     mounted(){ 
      var params = {id : this.$route.params.pageNum} 
      this.$store.dispatch("getEntries",params); 
     }, 
     methods: { 

      clicked(e){ 

       this.$router.push({ name: 'Entries', params: { pageNum: e.toString() }}); 

      }, 
      loadData(){ 
       var params = {pageNum : this.$route.params.pageNum} 
       this.$store.dispatch("getEntries", params) 
      } 
     }, 
     computed: { 
      items(){ 
       return this.$store.state.entries 
      }, 
     }, 
     watch: { 
      '$route': 'loadData' 
     } 
    } 


</script> 

順便說一句誤差來自:

Vue.config.errorHandler = function (err, vm, info) { 
    console.error(err); 
} 
+0

您確定負責該路線的代碼是正確和有效的嗎?當你手動進入'entry/13'時會發生什麼? –

+0

如果您的路線對象包含以下路線,應該可以工作:{path:'/ entry /:pageNum',name:'Entries'}。這是你使用的結構嗎? – Joos

+0

@BelminBedak如果我嘗試不同的命名路線它的作品。所以,我相信它是。 – serkan

回答

0

找到了答案。

似乎vue-router按預期工作。在我的情況下還有另一個問題。

如果我還有下面的代碼也genereic組件我相信它循環併產生一個錯誤。

watch: { 
     '$route': function(){ 
      this.loadData(); 
     } 
    } 

在我的情況下,我從通用組件中刪除了監視器,它工作。

相關問題