vue this.$router传参与接收


this.$router.push({name:'/xx/xx',query: {id:'1'}});
this.$router.push({name:'/xx/xx',params: {id:'1'}});
this.$router.push({path:'/xx/xx',query: {id:'1'}});
this.$router.push({path:'/xx/xx',params: {id:'1'}});
1.query方式传参和接受参数

this.$router.push({
 path:'/xxx'
 query:{
  idname:id
  }
})

接收的方式:this.$route.query
query类似于ajax中get传参,即在浏览器地址栏中显示参数。
2.params方式传递参数

this.$router.push({
 name:'路径名称'
 query:{
  idname:id
  }
})

接收的方式:this.$route.params
params则类似于post,即在浏览器地址栏中不显示参数。
注意:

  • 接收是用this.$route,不是this.$router
  • params用的是name进行的传递,这就意味着在router的js文件里,要给其加上name属性
    image


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM