動(dòng)態(tài)操作路由
//傳方
this.$router.push({ path: 'settleAccount', query: { customerId:obj.customerId}})
//收方
this.$route.query.customerId
//傳方
router.push({ name: 'user', params: { userId: 123 }})
//收方
this.$route.params.userId
注意:前者query傳參,會(huì)在頁面url上顯示參數(shù),后者params傳參則不會(huì),這代表刷新頁面前者參數(shù)存在,后者不存在
動(dòng)態(tài)匹配路由
const router = new VueRouter({
routes: [
// 動(dòng)態(tài)路徑參數(shù) 以冒號(hào)開頭
{ path: '/user/:id', component: User }
]
})
//收方
this.$route.params.id
注意:采用此種params傳參頁面地址欄會(huì)顯示,刷新后參數(shù)仍然存在