当前位置: 首页 > Web前端 > vue.js

this.$router.push获取不到params参数问题

时间:2023-04-01 01:04:15 vue.js

代码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:'容器',参数:{url:this.func.url,},});参数获取this.$route.params.urlthis.$router.push({path:'/container',query:{url:this.func.url,},});该方法会在重定向地址?url=xxxx获取方法this.$route.query.url上进行拼接,注意两种方法的区别,切勿让path和name同时出现