gpt4 book ai didi

vue.js - vue-router 具有不同参数的相同路由

转载 作者:行者123 更新时间:2023-12-02 11:25:46 26 4
gpt4 key购买 nike

我在 /entries/12路线。在同一个组件上,我想推送 /entries/13当用户单击下一步按钮时。

代码是这样的:

//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);
}

最佳答案

我用 :key 解决了我的问题.这样,我保证在 $route 更改时所有路由器 View 内容都将重新呈现。

<router-view :key="$route.fullPath" @showLoading="showLoading"></router-view>

关于vue.js - vue-router 具有不同参数的相同路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45432208/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com