Vue router 路由传递参数

简单介绍一下业务需求:

前端有一个列表页,每一行数据的标题都是一个文字按钮,点击后能够通过路由跳转到该数据对象的详情页中。我们要实现路由时通过路径传参,从而使详情页可以获取到必要的参数,来发送后续请求。

列表页绑定路由跳转的标题节点代码块如下所示:

<el-table>
	<el-table-column
	      label="MR 标题"
	      min-width="10%"
	      align="center">
	      <template v-slot="scope">
	         <el-button type="text" @click="$router.push(`/student/agile/${courseId}/gitcodecr/${scope.row.gitProjectId}/mrdetails/${scope.row.id}`)">
	           {{ scope.row.title }}
	         </el-button>
	      </template>
	   </el-table-column>
</el-table>

其中,对应的路由表如下:

{
	path: '/student/agile/:courseId/gitcodecr/:gitProjectId/mrdetails/:mrId',
	component: () => import('@/views/***/***/gitcodecr/details/Mrdetails'),
	props: true
},

上述代码可以看到,我们使用了 $router 向指定页面传递了三个参数,分别是:courseId、gitProjectId 以及 mrId。

在对应的下级界面中,我们仅需要通过 this.$route.params 的方式就可以获取这三个参数了。

this.courseId = this.$route.params.courseId;
this.gitProjectId = this.$route.params.gitProjectId;
this.mrId = this.$route.params.mrId;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值