1)直接在路由中傳參
this.$router.push({ path: `/childPage/${id}`, })
需要對應路由配置如下:
{ path: '/childPage/:id', name: 'childPage', component: childPage }
獲取參數:this.$route.parames.id
2) 通過路由屬性中的name來確定匹配的路由,通過params來傳遞參數
this.$router.push({ name: '', params: { id: id } })childPage
需要對應路由配置如下:
{
path: '/',childPage
name: '',childPage
component: childPage
}
3) 使用path來匹配路由,然后通過query來傳遞參數
this.$router.push({ path: '/', query: { id: id } })childPage
需要對應路由配置如下:
{
path: '/',childPage
name: '',childPage
component: childPage
}
獲取參數:this.$route.query.id
參考:https://segmentfault.com/a/1190000012393587?utm_source=tag-newest☺
