1.params傳參:
var id = this.tableDate[index].id;
this.$router.push({name:'testResult',params:{id:id}});
//目標頁面接受參數
let id = this.$route.params.id
路由動態傳參:
//路由
{
path: '/pay/:sellerId',
component: alliance,
meta: { title: '向商戶付款',wechat_auth: true, alipay_auth: true }
}
//獲取
this.sellerId = this.$route.params.sellerId;
2.query傳參:
//也可傳數組、對象
this.$router.push({
path:'/testResult',
query:{
sellerId: sellerId,
code: code,
payTool: payTool,
allianceData: this.allianceData //對象
}
});
//目標頁面接受參數
this.sellerId= this.$route.query.sellerId;
this.code= this.$route.query.code;
this.payTool= this.$route.query.payTool;
this.allianceData = this.$route.query.allianceData;
小結:
query傳參的參數會帶在url後邊展示在地址欄 (/page2?sellerId=xx&code=xxx&payTool=xxx)
params傳參的參數不會展示到地址欄