【发布时间】:2021-07-06 00:58:31
【问题描述】:
新手 Nuxt 问题:
我尝试使用不同的参数重定向到相同的路由,但不知道如何使用 $nuxt 来推送路由,所以我尝试了下面的 vue 路由器。
url 改变了,但是挂载的钩子没有被调用来改变数据
methods: {
changeMatch(event) {
this.$router.push({
name: "tran-dau-id-tuong-thuat",
params: { id: event.target.value },
});
},
更新:我关注https://router.vuejs.org/guide/essentials/dynamic-matching.html#reacting-to-params-changes
watch: {
$route(to, from) {
if (to.params.id != from.params.id) {
this.loadFixture();
}
},
},
【问题讨论】:
-
试试
updated钩子而不是mounted -
@BoussadjraBrahim 不起作用,因为它是相同的路由,因此组件将被重用,因此不会调用任何生命周期挂钩。