笔记:简述-Vue(vue-router)-$router与$route-params与query

$router与$route,前者似路由的发送者,后者似路由的接受者

//$router 路由跳转

this.$router.push();
this.$router.replace();
this.$router.go();
this.$router.back();
this.$router.forward();

//$route 路由参数接受
this.$route.params.id
this.$route.query.id

params与query,前者的参数在地址栏Url中隐藏键,后者显示键

this.$router.push({ name: 'user', params: { id: '123' }});
// http://xxxxx.com/user/123

this.$router.push({ path: 'user', query: { id: '123' }});
// http://xxxxx.com/user?id=123

!注意的一点是:params传递参数需要在路由文件中设置下地址参数

path: '/user/:id?',
component: xxxx


版权声明:本文为SLD_nmht原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。