1.params params傳參
跳轉(zhuǎn):
this.$router.push({ name: 'news', params: { userId: 123 }})
接收:
this.$route.params.name (在頁面刷新的時候就會消失)
2.router-link query傳參
跳轉(zhuǎn)
<router-link :to="{path:'/test',query: {name: id}}">跳轉(zhuǎn)</router-link>
this.$router.push({ path: 'news', query: { userId: 123 }})
接收
this.$route.query.name
3.路由傳參
//?問號的意思是該參數(shù)不是必傳項
//多個參數(shù)用/:id連接
this.$router.push({
path: `/describe/${id}`,
})
對應(yīng)路由下配置
{
path: '/describe/:id?',
name: 'Describe',
component: Describe
}
問號代表不是必填項
接收
頁面刷新不消失,可以在路由配置中設(shè)置參數(shù)
$route.params.id