vue-router 傳參

動(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ù)仍然存在

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容