Vue 路由传参

案例


this.$router.push({ name: 'anotherPage', params:{id: 1} })

this.$route.params.id

三种方法

方案一



this.$router.push({
    path: `/page2/${id}`,
})


{
    path: '/page2/:id',
    name: 'page2',
    component: page2
}


this.$route.params.id

方案二


this.$router.push({
    name: 'page2',
    params: {
        id: id
    }
})

{
    path: '/page2',
    name: 'page2',
    component: page2
}

this.$route.params.id

方案三



this.$router.push({
    path: '/page2',
    query: {
        id: id
    }
})
{
    path: '/page2',
    name: 'page2',
    component: page2
}
this.$route.query.id

你可能感兴趣的:(Vue 路由传参)