我在 /entries/12路线。在同一个组件上,我想推送 /entries/13当用户单击下一步按钮时。
代码是这样的:
//e is the next page number.
this.$router.push({ name: 'Entries', params: { pageNum: e }});
我得到以下错误:
如果我尝试不同的路线。
全码:
<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);
}
请您参考如下方法:
我用 :key 解决了我的问题.这样,我保证在 $route 更改时所有路由器 View 内容都将重新呈现。
<router-view :key="$route.fullPath" @showLoading="showLoading"></router-view>




