如果路由跳转使用path,必须使用query方式传参,如果使用name跳转,query和params都可以传参,建议使用query方式传参,query方式传参,参数在地址栏,当刷新页面后,参数还可以通过地址栏获取。
- path跳转,query传参
this.$router.push({
path : '/main',
query : {
userName : this.ruleForm.name
}
})
跳转到的页面:
{{this.$route.query.userName}}
- name跳转,query传参
this.$router.push({
name : 'Goodslist',
query :{
kw :item
}
})
跳转到的页面:
{{this.$route.query.kw}}
- name跳转,params传参
this.$router.push({
name : 'Goodslist',
params : {
kw : item
}
})
跳转到的页面:
{{this.$route.params.kw}}
本文介绍了在Vue.js中进行路由跳转时,如何使用query和params传递参数。强调了path跳转时应使用query方式,因为参数会显示在地址栏并可在页面刷新后继续获取。同时,name跳转时,query和params都是可行选项,但推荐使用query。

704

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



