方案一:直接調(diào)用$router.push 實現(xiàn)攜帶參數(shù)的跳轉(zhuǎn)
? this.$router.push({
? ? ? path: `/describe/${id}`,
? ? })
路由配置:
{
? ? path: '/describe/:id',
? ? name: 'Describe',
? ? component: Describe
? }
子組件獲取參數(shù):$route.params.id
方案二:通過路由屬性中的name來確定匹配的路由巫玻,通過params來傳遞參數(shù)
this.$router.push({
? ? ? ? ? name: 'Describe',
? ? ? ? ? params: {
? ? ? ? ? ? id: id
? ? ? ? ? }
? ? ? ? })
對應路由配置:
{
? ? path: '/describe',
? ? name: 'Describe',
? ? component: Describe
? }
子組件獲取參數(shù):$route.params.id
方案三:使用path來匹配路由痕惋,然后通過query來傳遞參數(shù)
這種情況下 query傳遞的參數(shù)會顯示在url后面?id=澈蚌?
this.$router.push({
? ? ? ? ? path: '/describe',
? ? ? ? ? query: {
? ? ? ? ? ? id: id
? ? ? ? ? }
? ? ? ? })
對應路由配置:
{
? ? path: '/describe',
? ? name: 'Describe',
? ? component: Describe
? }
子組件接收參數(shù):$route.query.id