vue 路由传参

[亡魂溺海] 提交于 2019-11-28 16:11:04

 

1,<router-link :to></router-link> 传参

:to="`/detail/${item.id}/${index}/${item.number}`"   
同时,route.js路由也要有相关的配置,
{
  path: '/detail/:id/:index/:type',
  name: 'detail',
  component: detail
}

2,编程式导航传参:

(1)  this.$router.push({
  path:`/newList/`,
  query:{
    id:this.id
  }
})

path 是路由配置项的路径,query就是需要传递的参数

 

(2)  this.$router.push({ path: `/newList/${this.id}` })  
 取参: this.$route.params,切记使用this.$route.query是取不到的
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!