今天重新过了一遍VueRouter的文档,梳理和总结了一下关于路由组件传参的一些思路,记下来防止以后忘记。
var param={name:{name:"111",age:"222",grade:"一年级"},age:12}
this.$router.push({name:"ChildContent",params:param})
this.$router.push({name:"ChildContent",query:param})
this.$router.push({path:"/ChildContent",params:param})
route.js
{
path: '/ChildContent/:id/post/:name',
component: ChildContent,
name:"ChildContent",
props:true //此时params就是组件的props
}
执行跳转的组件
var param={name:{name:"111",age:"222",grade:"一年级"},age:12}
this.$router.push({path:"ChildContent/123/post/456",query:param})
跳转到的组件
mounted(){
console.log(this.$route);
console.log(this.id,this.name);
},
props:["name","id","params"]
打印结果
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- nryq.cn 版权所有 赣ICP备2024042798号-6
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务