当前位置:   article > 正文

Vue中this.$router.push传参方式_this.$router.push 传参

this.$router.push 传参

1.params传参

var id = this.tableDate[index].id;
 
this.$router.push({name:'testResult',params:{id:id}});
 
//目标页面接受参数
let id = this.$route.params.id
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

路由动态传参:

//路由
{
  path: '/pay/:sellerId',
  component: alliance,
  meta: { title: '向商户付款',wechat_auth: true, alipay_auth: true }
}
 
//获取
this.sellerId = this.$route.params.sellerId;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

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;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

小结:
query传参的参数会带在url后边展示在地址栏 (/page2?sellerId=xx&code=xxx&payTool=xxx)

params传参的参数不会展示到地址栏

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/285140?site
推荐阅读
相关标签
  

闽ICP备14008679号