vue 路由跳转,传参

时间:2022-09-25 13:56:57
一.直接跳转
//js
1.this.$router.push('/ad_new') //html
2.<router-link to="/ad_check">
  <div class="top-menu-name">审核</div>
 </router-link>

二.跳转传参

query传参,参数会显示在url后面?id=?
this.$router.push({
path: '/member',
query: {
id: id
}
})
路由配置
{
path: '/member',
name: 'member',
component: member
}
接收参数
this.$route.query.id
push 直接传参

this.$router.push({
this.$router.push('/member/'+id);
}) 路由配置
{
path: '/member/:id',
name: 'member',
component: member
} 接收参数
this.$route.params.id
路由 name 

this.$router.push({
name: 'member',
params: {
id: id
}
}) 路由配置
{
path: '/member',
name: 'member',
component: member
} 接收参数
this.$route.params.id