1、$router和$route的区别session
$router : 是路由操做对象,只写对象
$route : 路由信息对象,只读对象
栗子:
//$router操做 路由跳转this
this.$router.push({ name:'hello', params:{ name:'word', age:'11' } })
//$route读取 路由参数接收url
var name = this.$route.params.name;
2、路由跳转方式name 、 path 和传参方式params 、query的区别code
*path 和 Name路由跳转方式,均可以用query传参
栗子:component
//Router.js { path: '/hello', name: 'HelloWorld', component: helloPage } 跳转方式name this.$router.push({ name: 'HelloWorld', query: { id: 12345 } }) 跳转方式path this.$router.push({ path: '/hello', query: { id: 12345 } }) //获取路由参数信息方式: {{$route.query.id}
*path路由跳转方式,params传参会被忽略,只能用name命名的方式跳转router
注意:params传参若是路由上面不写参数,也是能够传过去的,但不会在url上面显示出你的参数,而且当你跳到别的页面或者刷新页面的时候参数会丢失,要怎么解决?对象
解决:1、传参字符串name小的时候,能够在路由后面加参数名/router1/:name
2、name大的时候用sessionStorage;(欢迎补充)路由
注意:若是路由为动态路由{path: '/hello/:id',name:'hello'}
路由跳转执行this.$router.push({name: 'hello',params: obj});obj里面只要有id属性,就会自动带到URL里面字符串