vue中點擊頁面跳轉(zhuǎn)傳參,可以通過設置params 與query
params方式
獲取params傳值方式?this.$route.params.xxx ,
1 在路由配置文件中設置在path中。
? ? ? ? {
?????????routes: [
????????????{
????????????????path: "/news/:type?? ?// ? 表示type可選,可傳可不傳
????????????????component: News,
????????????????props: true
????????????},
?????????????...
????????????]
????????}
2? ?<router-link?
? ? ? ? ? ? :to="{name:'news',params:{type:'sports'}}"
? ? ? ?>
? ? ? ? 體育新聞
? ? </router-link>
? ? ?ps:該router-link情況下,params在name(為路由名稱)指定情況下使用,不能通過指定path情況使用
3 通過在this.$router.push等方法下使用
query方式
獲取params傳值方式?this.$route.query.xxx?
1 指定在router-link?
????<router-link?
????????:to="{path:'/news',query:{type:'sports'}}"
????>
????????體育新聞
????</router-link>
2? ?通過在this.$router.push等方法下使用
不管是params? query,為了與this.$route解耦 ,可以利用上面的指定props的方式,通過屬性獲取
,