相思资源网 Design By www.200059.com

背景

在开发提分加项目的过程中,遇到了点击下拉菜单时在新窗口中打开页面,由于之前一直做的是单页面应用,没有碰到过类似的需求,于是上网搜了一下解决办法,也再次系统地温习了一下vue-router。

Vue中在新窗口打开页面及Vue-router的使用

Vue中在新窗口打开页面及Vue-router的使用

解决

使用路由对象的resolve方法解析路由,可以得到location、router、href等目标路由的信息。得到href就可以使用window.open开新窗口了。

const {href} = this.$router.resolve({
 name: "statistics-explain",
 params: {
 classID: id,
 examSubjectID: this.planClassData.examSubjectID,
 studentStatus: 0
 }
});
window.open(href, '_blank');

延伸

参考文章:Vue Router

"htmlcode">

export default {
path: '/scoreplus',
name: 'scoreplus',
component: { template: '<router-view />' },
redirect: { name: 'scoreplus-index' },
children: [
 {
 // 查看个人方案
 path: 'preview/:examSubjectID/:xuexinID/:recordsID/:constitute/:planID',
 name: 'score-preview',
 meta: { text: '个人方案' },
 component: ScorePreview
 },
 {
 // 查看方案内容
 path: 'planList/:planID',
 name: 'score-plan-list',
 meta: { text: '查看方案内容' },
 component: ScorePlanList
 },
 {
 // 下载方案内容
 path: 'download/:planID/:classID',
 name: 'score-download-list',
 meta: { text: '下载方案内容' },
 component: DownloadList
 },
 {
 // 查看推送试题
 path: 'push/:planID/:level',
 name: 'score-question-push',
 meta: { text: '查看推送试题' },
 component: QuestionPush
 },
 {
 // 提分方案首页
 path: '',
 name: 'scoreplus-index',
 component: ScoreIndex
 }
]
}

"htmlcode">

// 字符串
router.push('home')
// 对象
router.push({ path: 'home' })
// 命名的路由
router.push({ name: 'user', params: { userId: 123 }})
// 带查询参数,变成 /register"htmlcode">
<router-link :to="{ name: 'user', params: { userId: 123 }}">User</router-link>
router.push({ name: 'user', params: { userId: 123 }})

"htmlcode">

 const router = new VueRouter({
 routes: [
 { path: '/a', redirect: '/b' }
 ]
 })

2.别名:/a 的别名是 /b,意味着,当用户访问 /b 时,URL 会保持为 /b,但是路由匹配则为 /a,就像用户访问 /a 一样。

 const router = new VueRouter({
 routes: [
 { path: '/a', component: A, alias: '/b' }
 ]
 })

总结

以上所述是小编给大家介绍的Vue中在新窗口打开页面及Vue-router的 使用,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

标签:
vue新窗口打开页面,vue,router

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“Vue中在新窗口打开页面及Vue-router的使用”

暂无Vue中在新窗口打开页面及Vue-router的使用的评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。