路由跳转传参(传文章id或者地址id到文章详情页或地址修改栏)
有两种方式
vue中自带的:
:to="{
name: 'article',
params: {
articleId: article.art_id
}
}"
或是自己写的:
this.$router.push({
name: 'editAddress',
params: {
addressId: item.id
}
})
方式一:
`this.$route.params.articleId`
方式二:
props 传参
在路由中开启props传参
{
path: '/article/:articleId',
name: 'article',
component: () => import('@/views/article/'),
// 将动态路由参数映射到组件的 props 中,无论是访问还是维护性都很方便
// 参考文档:https://router.vuejs.org/zh/guide/essentials/passing-props.html
props: true,
meta: { requiresAuth: false }
},
然后直接写
props: {
articleId: {
type: [String, Number, Object],
required: true
}