本篇介绍vue router的动态绑定。
动态传值。
之前一篇vue router基础讲了页面内路由的配置方法以及路由的入口,在这里就不多陈述了。
1、配置路由
2、路由入口
3、动态获取对象传值
mouted(){
this.$route.params;
}
编程实现路由获取对象
gorouter() {
this.$router.push("/"); //1.push 方法里面直接写路由的路径
this.$router.push({path:"/"});//2.push 方法里面写对象{path:"/"}
//3.跳转的时候携带参数-get传值式写法
this.$router.push({
path: "/",
query: {id: 1}
});
//4.编程时里面的动态路由传值
this.$router.push({
path: "/my/100" //这种在跳转的时候,必须保持和路由配置上的参数一致
});
}
传回对象:
mounted(){ this.$route.query; }
get传值:
路由入口:
//对象的方式传递
<router-link :to="{'path':'/detail',query:{'id':item.id,'name':item.name}}">{{item.name}}</router-link>
传回对象:
mounted(){ this.$route.params; }
子父路由
{
name:"dingdan",
path:"/ding",
component:Productor,//子父路由 比如在我的订单界面配置子父路由 自路由显示在父路由组件的内部
children:[
{
path:"/ding/cart",
component:Cart
}
]
}