gpt4 book ai didi

vue.js - 在 vue js 上观察路由对象

转载 作者:搜寻专家 更新时间:2023-10-30 22:18:23 24 4
gpt4 key购买 nike

如何在 vue js 上查看路由对象?。这是我的代码

watch: { 
'$route.params.search': function(search) {
console.log(search)
}
}

它不起作用。

我尝试使用 deep 仍然无法处理 here

查看代码沙箱,您可以在 main.js 上查看路由对象。

You should not watch for the route object inside any other components. Because components get destroyed when router link changes. You should do it in the main.js file, according to your directory structure

感谢@santanu 和@ittus

最佳答案

您是否尝试过deep选项?

watch: { 
'$route.params.search': {
handler: function(search) {
console.log(search)
},
deep: true,
immediate: true
}
}

关于vue.js - 在 vue js 上观察路由对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50981059/

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