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"}
 })

地址栏会显示相应参数

VUE - 路由传参的三种方式

获取参数

this.$route.query.from

 

 

 

 3. params

使用 name 来匹配路由

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

地址栏不会显示参数

获取参数

this.$route.params.from

 

相关文章:

  • 2022-12-23
  • 2021-08-16
  • 2021-08-21
  • 2021-12-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2022-01-03
相关资源
相似解决方案