欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 能源 > vue 跳转页面-$router.resolve和$router.push区别

vue 跳转页面-$router.resolve和$router.push区别

2025/4/20 14:21:55 来源:https://blog.csdn.net/weixin_45403802/article/details/141436941  浏览:    关键词:vue 跳转页面-$router.resolve和$router.push区别

打开方式

router.push 只能当前窗口打开router.resolve 结合 window.open 可以新窗口打开

参数传递

router.push 支持query和paramsrouter.resolve 只支持query,若需地址栏参数不可见,需结合localStorage或第三方插件保存

this.$router.push

// 地址栏里带参
this.$router.push({path: '这里是path',query: {a: 1,},
});// 地址栏里不带参
this.$router.push({name: '这里是name',params: {a: 1,},
});

注:
this.$ router.push用query传参对象时需注意的地方
用函数式编程this.$router.push跳转,用query传递一个对象时要把这个对象先转化为字符串,然后在接收的时候要转化为对象,要不然会接收不到参数。要不就把参数分开传递,不要放到对象里。

this.$router.push({path: '/liveing',query: {routeParams: JSON.stringify({ liveUrl: url, flag: 2 })}
});

接收:

let routeParams = JSON.parse(this.$route.query.routeParams)
this.currMeetingUrl = routeParams.liveUrl; 
this.obcject = routeParams.flag;

第二种方法:不要套在对象里直接传递

this.$router.push({path: '/liveing',query: {liveUrl: url, flag: 2}
});

接受:

let liveUrl = this.$route.query.liveUrl;
let flag = this.$route.query.flag;

this.$router.resolve

// 地址栏里带参
let data = this.$router.resolve({path: "/channel_sms",// 或者 name: 'channel_sms',query: {a: 1,},
});
window.open(data.href, '_blank');// 地址栏里不带参
let data = this.$router.resolve({name: 'channel_sms',
});
localStorage.setItem('a', 1);
// 然后跳转页接收 localStorage.getItem('a');

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词