路由传参(一)

路由传参分为query传参和params传参

一 .使用query传参

  1. 地址栏显示:
    在这里插入图片描述
  2. 路由跳转
<el-button type="text" size="small" @click="$router.push(`/employees/detail?id=${row.id}`)">查看</el-button>```
  1. 使用query传参就不需要额外配置路由规则,不用在路由规则中写参数
export default {
  path: '/employees',
  component: Layout,
  children: [
    {
      path: '', // 要么就空着, 要么就写全
      name: 'employees',
      component: () => import('@/views/employees'),
      meta: { title: '员工', icon: 'people' }
    },
    {
      path: 'detail', // 不写/ 会自动拼接成'/employees/detail'
      name: 'detail',
      hidden: true,
      component: () => import('@/views/employees/detail')
      // meta: { title: '查看详情', icon: 'people' }
    }
  ]
}
  1. query传参获取参数
<template>
  <div class="detail">
    查看详情 {{ $route.query.id }}
  </div>
</template>

二. 使用params传参

  1. 地址栏显示:
    在这里插入图片描述
  2. 路由跳转
<el-button type="text" size="small" @click="$router.push(`/employees/detail/${row.id}`)">查看</el-button>
  1. 使用params传参,路由规则中必须做 /:id的占位
path: '/employees/detail/:id' // 动态参数匹配
  1. params传参获取参数
<template>
  <div class="detail">
    查看详情 {{ $route.params.id }}
  </div>
</template>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值