vue路由跳转以新页面打开参数传递

本文详细介绍在Vue项目中如何通过GET和POST方式在不同页面间传递参数,提供了具体的代码示例,帮助开发者掌握跨页面通信技巧。

vue中打开新页面以post形式传递参数

const href = this.$router.resolve({
	name:'跳转路径',//此为Router路由配置文件中对应的name值
	params:{
		参数名:值,
		参数名:值,
		.....
	}
})
window.open(href.href, '_blank')

vue中打开新页面以get形式传递参数

const href = this.$router.resolve({
	path:'跳转路径',//此为Router路由配置文件中对应的name值  格式/path
	query:{
		参数名:值,
		参数名:值,
		.....
	}
})
window.open(href.href, '_blank')

欢迎大家访问我的个人博客http://blog.ycsn.xyz/

Vue中实现路由跳转打开新窗口,可借助`this.$router.resolve`方法生成路由的完整URL,再使用`window.open`方法在新窗口打开该URL。以下是几种不同场景下的示例代码: ### 无参数跳转 ```vue <template> <button class="btns" type="button" @click="openNewWindow">打开新窗口</button> </template> <script> export default { methods: { openNewWindow() { let routerData = this.$router.resolve({ path: '/pkgeffective' }); window.open(routerData.href, '_blank'); } } } </script> ``` ### 带查询参数跳转 ```vue <template> <button class="btns" type="button" @click="openNewWindowWithParams">带参数打开新窗口</button> </template> <script> export default { methods: { openNewWindowWithParams() { let id = '123'; const { href } = this.$router.resolve({ path: '/home/test', query: { id: id } }); window.open(href, '_blank'); } } } </script> ``` ### 结合组件内方法和事件的跳转 ```vue <template> <button class="btns" type="button" @click="showLogdialog">登录</button> </template> <script> export default { methods: { showLogdialog() { let routeUrl = this.$router.resolve({ path: '/Login', query: { companyName: 'Login' } }); window.open(routeUrl.href, '_blank'); } } } </script> ``` ### 基于表格行数据的跳转 ```vue <template> <table> <thead> <tr> <th>ID</th> <th>操作</th> </tr> </thead> <tbody> <tr v-for="row in tableData" :key="row.id"> <td>{{ row.id }}</td> <td><button @click="handleLink(row)">查看</button></td> </tr> </tbody> </table> </template> <script> export default { data() { return { tableData: [ { id: 1 }, { id: 2 }, { id: 3 } ] }; }, methods: { handleLink(row) { let link = this.$router.resolve({ path: '/user', query: { id: row.id } }); window.open(link.href, '_blank'); } } } </script> ```
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

透过代码观世界

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值