路由传值的方式有哪几种


Vue-router传参可以分为两大类,分别是编程式的导航 router.push和声明式的导航
1、router.push
1.1)字符串:直接传递路由地址,但是不能传递参数
this.$router.push("home")
对象:
1.2)命名路由 这种方式传递参数,目标页面刷新会报错
this.$router.push({name:"news",params:{userId:123})
1.3)查询参数 和name配对的式params,和path配对的是query
this.$router.push({path:"/news',query:{uersId:123})
1.4)接收参数 this.$route.params this.$route.query
2、声明式导航
2.1)字符串 <router-link to="news"></router-link>
2.2)命名路由 <router-link :to="{name:'news',params:{userid:1111}}"></router-link>
2.3)查询参数 <router-link :to="{path:'/news',query:{userId:1111}}"></router-link>


免责声明!

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



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