Vuejs-router传参方式
1.使用query传参
使用query传递参数时,在地址栏可以看到参数≈get方式传输
this.$router.push({
path:'/XXX'
query:{
name:'yaoxx'
}
})
/XXX中接收参数代码:
this.$route.query.name; //ps:传参用$router,但是接收用$route
2.使用params
貌似params是使用配置文件中的【name】而非【path】跳转,所以注意别写错
this.$router.push({
name:'XXX' //配置文件中的name
params:{
name:'yaoxx'
}
})
/XXX中接收参数代码:
this.$route.params.name; //ps:传参用$router,但是接收用$route