Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

vue 获取当前路由

作者:霸气邪剑仙   发布日期:2025-05-17   浏览:30

// 在 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 全局方法

大家都在看

vue.config.js configu

node.js vue

vue查看版本

vue等待几秒

vue3 setup computed

vue screenfull

vue json.stringify

vue 遍历list

typescript vue

vue 复选框

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站