首页 > 其他 > 详细

VUE - 路由传参的三种方式

时间:2020-03-10 21:51:43      阅读:51      评论:0      收藏:0      [点我收藏+]

1.  在路由中配置 path

{
    path:‘product/:id‘,
    name:"product",
    component:Product,
},

 传递参数,页面刷新数据不会消失

  getProductInfo(){
     // 获取路由参数
     let id = this.$route.params.id;
     this.axios.get(`/products/${id}`).then(res=>{
        this.product = res
     })
  },    

获取参数

this.$route.params.id

 

2.  query

使用 path 来匹配路由

 this.$router.push({
     path:‘/index‘,
     query:{from:"login"}
 })

地址栏会显示相应参数

技术分享图片

获取参数

this.$route.query.from

 

 

 

 3. params

使用 name 来匹配路由

this.$router.push({
     name:‘index‘,
     params:{from:"login"}
})

地址栏不会显示参数

获取参数

this.$route.params.from

 

VUE - 路由传参的三种方式

原文:https://www.cnblogs.com/-xiao/p/12458660.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!