vue3 中获取当前路由地址避坑——router.currentRoute与$route
1.router.currentRoute 相当于 $route但是$route.path或者$route.fullPath只能在组件中用组件里头:`/user?a=10` $route.path === /user$route.fullPath === /user?a=10js模块中要使用 router.currentRoute// js模块中:router.currentRoute.value
·
1.router.currentRoute 相当于 $route
但是$route.path或者$route.fullPath只能在组件中用
组件里头:`/user?a=10` $route.path === /user $route.fullPath === /user?a=10
js模块中要使用 router.currentRoute
// js模块中:router.currentRoute.value.fullPath 就是当前路由地址
2.router.currentRoute是ref响应式数据 要拿值的话需要.value
3.encodeURIComponent 转换uri编码,防止解析地址出问题 用来解析获得的fullPath中的特殊字符
const fullPath = encodeURIComponent(router.currentRoute.value.fullPath)
更多推荐
所有评论(0)
您需要登录才能发言
加载更多