vue-router传参数(get和post方式)
vue-router传参数(get和post方式)本文主要介绍vue-router传参数的两种方式:1、get方式页面跳转this.$router.push({path:'/xxx',query:{id:1}});//类似get传参,通过URL传递参数新页面接收参数this.$route.query.id2、post方式页面跳转
·
vue-router传参数(get和post方式)
本文主要介绍vue-router传参数的两种方式:
1、get方式
页面跳转
this.$router.push({path:'/xxx',query:{id:1}});//类似get传参,通过URL传递参数
新页面接收参数
this.$route.query.id
2、post方式
页面跳转
//由于动态路由也是传递params的,所以在 this.$router.push() 方法中 path不能和params一起使用,否则params将无效。
需要用name来指定页面。 this.$router.push({name:'page2',params:{id:1}});//类似post传参
新页面接收参数
this.$route.params.id
3、注意:在页面进行刷新的时候经常会遇到参数变了,但是新页面接受的参数没有变化。这种问题可以通过加watch解决。
watch: { '$route'(to, from){ //在这里重新刷新一下 this.getParams(); } }
更多推荐
已为社区贡献16条内容
所有评论(0)