// 在 Vue 中获取当前路由,通常使用 vue-router 提供的 $route 对象。
// 以下是一个简单的示例代码:
// 假设你已经安装并配置好了 vue-router
// 在你的 Vue 组件中,你可以通过 this.$route 来访问当前路由信息
export default {
mounted() {
// 获取当前路由的完整路径
console.log(this.$route.path);
// 获取当前路由的名称
console.log(this.$route.name);
// 获取当前路由的参数(如果有的话)
console.log(this.$route.params);
// 获取查询参数(例如:/some/path?foo=bar)
console.log(this.$route.query.foo);
}
}
this.$route
是一个包含当前路由信息的对象。this.$route.path
返回当前路由的路径(例如 /home
)。this.$route.name
返回当前路由的名称(如果你在定义路由时设置了名称)。this.$route.params
返回当前路由的动态参数(例如 /user/:id
中的 id
)。this.$route.query
返回 URL 查询参数(例如 /some/path?foo=bar
中的 foo=bar
)。上一篇:vue3 sass
下一篇:vue3 全局方法
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站