一、顺便提一嘴$router和$route的区别
//$router : 是路由操作对象,只写对象
//$route : 路由信息对象,只读对象
//操作 路由跳转
this.$router.push({
name:'hello',
params:{
name:'word',
age:'11'
}
})
//读取 路由参数接收
this.name = this.$route.params.name;
this.age = this.$route.params.age;
二、params和query的区别
使用params传参,只能使用name跳转,参数不显示在url上面,但是刷新页面参数丢失:
//params传参 使用name
this.$router.push({
name:'second',
params: {
id:'1',
name: '2'
}
})
//params接收参数
this.id = this.$route.params.id ;
this.name = this.$route.params.name ;
修改路由后,参数不丢失,但是参数会显示在url上面,如: