文章目录

  • 基本用法:
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)
	}
}
Logo

前往低代码交流专区

更多推荐