this.$router.push获取不到params参数问题
文章目录
代码
this.$router.push({
path: '/container',
params: {
url: this.func.url,
},
});
在跳转后的页面中console.log(this.route)发现params是空的
问题原因:用法错误,以下为正确用法
this.$router.push({
name: 'container',
params: {
url: this.func.url,
},
});
要使跳转后的页面this.$route.params有参数,必须使用name:'container',而不是path:'/container',还需要注意name中没有/
this.$router.push({
name: 'container',
params: {
url: this.func.url,
},
});
参数获取this.$route.params.url
this.$router.push({
path: '/container',
query: {
url: this.func.url,
},
});
这种方式会在跳转的地址上拼接上?url=xxxx
获取方式this.$route.query.url
注意区别两种方式,切勿path和name同时出现

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论