有时候开发需要获取当前url的参数
完整url可以用
window.location.href
路由路径可以用
this.$route.path
路由路径参数
this.$route.params
(params是参数名称)
也可以直接watch监听一下当前路由的信息
watch:{
$route(to, from) {
console.log(window.location.href);
console.log(this.$route.path);
console.log(this.$route.params);
}
}
本文介绍了在前端开发中如何使用window.location.href获取完整的URL,使用this.$route.path获取路由路径,以及通过this.$route.params获取路由参数的方法。此外,还讲解了如何设置watch监听器来实时获取和打印当前路由的信息。
2197

被折叠的 条评论
为什么被折叠?



