文章目录
基本用法:watch{$route(now,old){// now: 变化之后的数据// old: 变化之前的数据console.log(now,old)}}
$route
的数据结构如下:
console.log(this.$route){fullPath: "/main-home",hash: "",matched: [],meta: {},name: "HomePage",params: {},path: "/main-home",query: {},}
所以,如果我们只监听path
路径,可以这样写
watch{'$route.path'(now,old){// now: 变化之后的数据// old: 变化之前的数据console.log(now,old)}}
如果觉得《【Vue】watch 监听 url 地址参数变化(路由变化)》对你有帮助,请点赞、收藏,并留下你的观点哦!