1.query方式传参和接收参数
传参:
this.$router.push({
path:'/xxx',
query:{
id:id
}
})
接收参数:
this.$route.query.id
注意:传参是this.$router,接收参数是this.$route,这里千万要看清了!!!
this.<mjx-container class="MathJax" jax="CHTML" style="font-size: 113.1%;"><mjx-math class="MJX-TEX"><mjx-mo class="mjx-n" space="4"><mjx-utext variant="normal" style="font-size: 88.4%; padding: 0.848em 0px 0.226em; font-family: MJXZERO, serif;">和</mjx-utext></mjx-mo></mjx-math></mjx-container>route有何区别?
在控制台打印两者可以很明显的看出两者的一些区别:


- 1.router为vue Router实例,想要导航到不同的url,则使用router.push方法
- 2.$route为当前router跳转对象,里面可以获取name、path、query、params等
2.params方式传参和接收参数
传参:
this.$router.push({
name:'xxx',
params:{
id:id
}
})
接收参数:
this.$route.params.id
注意:params传参,push里面只能是 name:'xxxx',不能是path:'/xxx',因为params只能用name来引入路由,如果这里写成了path,接收参数页面会是undefined!!!
网友评论