手记

vue动态路由传参,这两种方式你试过吗

    今天来给大家说说vue动态路由传参的两种方式

1.query传参:相当于get 必须定义path属性,通过query传参 通过 this.$route.query 接收参数

2.params传参:必须定义 name 属性,通过params传参 通过 this.$route.params接收参数

第一种方式

props:ture (这种模式在进行参数传递的时候切记得是params这种模式 query这种模式不生效)

//在router/index.js的传参组件页面添加

new Router({

 routes:[

 {path:‘/index’,

 name:"form"

  component:()=>import('@view/form/index');

  props:ture//开启组件参数传递

 }

]

})

第二种方式

通过函数的方式

new Router({

routes:[

{path:‘/index’,

name:"form"

component:()=>import('@view/form/index');

props:(route)=>{

return {

user:route.query.user //将传递过来的数据通过返回值的形式进行返回

}//开启组件参数传递

}

]

})


0人推荐
随时随地看视频
慕课网APP