【发布时间】:2021-04-19 13:39:42
【问题描述】:
我正在尝试使用我的搜索输入访问不同用户的用户,我可以在其中键入用户的名称,然后单击任何结果并导航到他们的页面。显示第一个用户页面,但是当我搜索另一个用户并单击用户名时,地址栏中的路线会更新,但窗口中的视图仍显示较早的用户。我的代码做错了什么?
<template>
<div>
<custom-component :users="users" @input="onClick"></custom-component>
</div>
</template>
<script>
export default {
methods: {
onClick(id) {
this.$router.push(`/user/${id}`);
},
},
watch: {
$route(to, from) {
if (to.params.id !== from.params.id) {
this.$router.push(to.fullPath);
}
},
},
};
【问题讨论】:
标签: vue.js vuejs2 vue-router vuejs3