this.$router.push() 跳轉(zhuǎn)與傳參
<router-link :to> 點(diǎn)擊時(shí)會(huì)在內(nèi)部調(diào)用,相當(dāng)于router.push(),一個(gè)是聲明式寫法周伦,一個(gè)是編程式寫法赴涵。
<router-link :to='{ path:'/' 圃阳,query:data}'></router-link>
query傳參(會(huì)顯示在地址欄路徑里)
this.$router.push({
path:'/' //路由路徑岛琼,
query:data //傳參
})
data:{
id:‘1’
}
params傳參(不顯示在路徑里)
由于動(dòng)態(tài)路由也傳遞params的败匹,所以this.$router.push()方法中path不能和params一起使用症杏,否則params則無用豫尽,需要配置name來指定頁面
//配置name
{
path:'./index',
name:'home',
component:index
}
//使用
this.$router.push({
name:'home',
params:{id:'1'}
})
接收參數(shù)
this.$route.params.id
this.$route.query.id