1 路由跳转
1.1 单纯跳转
//router-link:路由跳转方式
this.$router.push("bookDetail");
1.2 路由跳转带参数
1.2.1 通过path
this.$router.push({path:"/bookDetail",query:{bookId:id}})
接收
this.bookId = this.$route.query.bookId;
1.2.2 通过name跳转路由
this.$router.push({name:"bookDetail",query:{bookId:id}})
接收
this.bookId = this.$route.query.bookId;
1.2.3 通过params
this.$router.push({name:"bookDetail",params:{bookId:id}})
接收
this.bookId = this.$route.params.bookId;
params传参,push里面只能是 name:‘xxx’,不能是path:‘/xxx’,因为params只能用name来引入路由,如果这里写成了path,接收参数页面会是undefined
2 $router和$route区别
$router : 是路由操作对象,只写对象
$route : 路由信息对象,只读对象
query相当于GET请求,页面跳转的时候,可以在地址栏看到请求参数
params相当于POST请求,参数不会在地址栏中显示
本文详细介绍了VueRouter中的路由跳转方法,包括单纯跳转、带参数的路径和名称跳转,以及query和params的区别,指出params用于POST请求,而query用于GET请求且参数不会显示在URL中。
344

被折叠的 条评论
为什么被折叠?



