背景
在开发提分加项目的过程中,遇到了点击下拉菜单时在新窗口中打开页面,由于之前一直做的是单页面应用,没有碰到过类似的需求,于是上网搜了一下解决办法,也再次系统地温习了一下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">
"htmlcode">
2.别名:/a 的别名是 /b,意味着,当用户访问 /b 时,URL 会保持为 /b,但是路由匹配则为 /a,就像用户访问 /a 一样。 总结 以上所述是小编给大家介绍的Vue中在新窗口打开页面及Vue-router的 使用,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
// 字符串
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 }})
const router = new VueRouter({
routes: [
{ path: '/a', redirect: '/b' }
]
})
const router = new VueRouter({
routes: [
{ path: '/a', component: A, alias: '/b' }
]
})
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 群星.1991-不一样的感觉REMIX【宝丽金】【WAV+CUE】
- 银霞.1983-《你那好冷的小手》珍藏纪念版[WAV分轨]
- 银霞.2002-《国语巨星专辑VOL.3》2CD台湾版[WAV+CUE]
- 金池刘罡《昨日情歌HQ》头版限量编号[低速原抓WAV+CUE]
- 段奥娟.2024-23·岁碎念【白米范】【FLAC分轨】
- 顺子.2001-昨日·唯一·更多·顺子自选辑【魔岩】【WAV+CUE】
- 无印良品.1999-私藏三首·原创相对论(EP)【滚石】【WAV+CUE】
- Merryland《Merryland》[FLAC/分轨][170.22MB]
- 庄锭欣 ELKIE《没有你的未来》[320K/MP3][15.78MB]
- 庄锭欣 ELKIE《没有你的未来》[FLAC/分轨][36MB]
- TchaikovskySwanLake,Op.20柴可夫斯基天鹅湖(2013)SACD[Hi-Res]
- 24bit达人艺典《琴歌终极版》整轨WAV+CUE
- 黑鸭子.2005-《发烧DSD》柏菲[WAV分轨]
- 群星.1990-电影看板·人间道【宝丽金】【WAV+CUE】
- 周殷廷.2024-TO.WHOM.IT.MAY.CONCERN【环球】【FLAC分轨】