应无所住,而生其心
排名
1
文章
860
粉丝
112
评论
163
net core webapi post传递参数
庸人 : 确实坑哈,我也是下班好了好几次,发现后台传递对象是可以的,但...
百度编辑器自定义模板
庸人 : 我建议换个编辑器,因为现在百度富文本已经停止维护了,用tinymec...
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术

windows对象中获取vue对象。vue中使用iframe页面嵌套后,嵌套页里边页面跳转问题,实现外层路由的跳转,实现打开新的tab页面

3368人阅读 2020/11/10 9:55 总访问:5182664 评论:0 收藏:0 手机
分类: 前端

某些情况下使用iframe可以降低一下耦合度,分隔开项目,不会让一个项目越来越大。

vue嵌套iframe页面的方法

比如这里的path就是需要使用iframe打开的路由,是因为路由的规则就是这样设置的

这一串:routerPath里边的内容才是真正iframe引用的内容,也就是这一串内容

贴一下主项目那个iframe的实现:

  1. <template>
  2. <div>
  3. <iframe ref="iframe" v-loading.fullscreen.lock="fullscreenLoading" :src="getUrlPath()" class="iframe" />
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. components: {},
  9. props: {
  10. routerPath: {
  11. type: String,
  12. default: ''
  13. }
  14. },
  15. data() {
  16. return {
  17. fullscreenLoading: false,
  18. urlPath: this.getUrlPath()
  19. }
  20. },
  21. watch: {
  22. routerPath: function(val) {
  23. console.log(val)
  24. this.urlPath = this.getUrlPath()
  25. }
  26. },
  27. created() {
  28. this.src = this.$route.query
  29. console.log('ifram', this.$route)
  30. this.fullscreenLoading = false
  31. },
  32. mounted() {
  33. console.log(this.$route, this.routerPath)
  34. this.iframeInit()
  35. window.onresize = () => {
  36. this.iframeInit()
  37. }
  38. // 方法让子页面可以调用
  39. window.jumpUrl = this.jumpUrl
  40. },
  41. methods: {
  42. jumpUrl(_path, _query) {
  43. // 进行页面跳转
  44. this.$router.push({
  45. path: _path,
  46. query: _query
  47. })
  48. // router.push({
  49. // path: '/task_report/schoolMonthTaskReport',
  50. // query: {
  51. // dateTime: _dateParamDay,
  52. // type: _type,
  53. // dateParamChoise: state.dateParamChoise,
  54. // isJumpQueryDetails: "1"
  55. // }
  56. // })
  57. },
  58. iframeInit() {
  59. const iframe = this.$refs.iframe
  60. const clientHeight = document.documentElement.clientHeight - 90
  61. iframe.style.height = `${clientHeight}px`
  62. if (iframe.attachEvent) {
  63. iframe.attachEvent('onload', () => {
  64. this.fullscreenLoading = false
  65. })
  66. } else {
  67. iframe.onload = () => {
  68. this.fullscreenLoading = false
  69. }
  70. }
  71. },
  72. getUrlPath: function() {
  73. // let url = window.location.href
  74. let url = `/${this.$route.params.routerPath}`
  75. // url = url.replace('/iframe', '')
  76. var timstamp = (new Date()).valueOf()
  77. if (url.indexOf('?') >= 0) {
  78. url = url + '&t=' + timstamp
  79. } else {
  80. url = url + '?t=' + timstamp
  81. }
  82. console.log(url)
  83. return url
  84. }
  85. }
  86. }
  87. </script>
  88. <style>
  89. .iframe {
  90. width: 100%;
  91. height: 100%;
  92. border: 0;
  93. overflow: hidden;
  94. box-sizing: border-box;
  95. }
  96. </style>

vue中使用iframe页面嵌套后,嵌套页里边页面跳转不会在外部项目打开tab页面,只会在iframe页面里边刷新因为他其实是不同的项目,要实现外层路由的跳转,实现打开新的tab页面,肯定要想办法能操作到主项目的vue对象也就是外层项目的vue对象,一般有两种实现方法。

一种是在iframe中嵌套获取顶层的vue对象,获取到vue对象就可以操作路由进行页面跳转了

在主项目中,main.js里边把vue的对象存放到windows里边去。

然后嵌套的iframe页面里边就可以使用window.top.vm获取到顶层的vue对象了

获取到顶层对象了就可以进行正常情况的跳转了。

还有一种就是在主项目提供一个方法,让嵌套的iframe页面来调用方法

参考:https://blog.csdn.net/pk694046220/article/details/128578108

  1. mounted() {
  2. console.log(this.$route, this.routerPath)
  3. this.iframeInit()
  4. window.onresize = () => {
  5. this.iframeInit()
  6. }
  7. // 方法让子页面可以调用
  8. window.jumpUrl = this.jumpUrl
  9. },
  10. methods: {
  11. jumpUrl(_path, _query) {
  12. // 进行页面跳转
  13. this.$router.push({
  14. path: _path,
  15. query: _query
  16. })
  17. // router.push({
  18. // path: '/task_report/schoolMonthTaskReport',
  19. // query: {
  20. // dateTime: _dateParamDay,
  21. // type: _type,
  22. // dateParamChoise: state.dateParamChoise,
  23. // isJumpQueryDetails: "1"
  24. // }
  25. // })
  26. }
  27. }

欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)

评价

windows平台分布式架构实践 - 负载均衡

原文地址: https://www.cnblogs.com/atree/p/windows_loadbalancer.html 概述  最近.NET的世界开始闹腾了,微软官方终...

.NET windows服务发布、安装、卸载、监听脚本。服务调试

一、脚本 为方便不用每次都去写安装卸载的脚本1.安装脚本@echooff @echo开始安装【服务】 %SystemRoot%\Microsoft.NET\Fr...

windows下Redis的主从复制

Redis拥有非常强大的主从复制功能,而且还支持一个master可以拥有多个slave,而一个slave又可以拥有多个slave,从而形成强...

Redis基础安装操作-windows

一、下载 redis官方没有提供windows版本,需要从微软的git下载releases版二、安装,启动1.解压出来 启动服务 可能会双击会...

windows 自带的netsh进行端口映射

使用netsh 把本地任意ip的25566端口 映射到192.168.81.234的25565端口netshinterfaceportproxyaddv4tov4listenaddress=0.0....

windows使用wireshark抓包小心得

wireshrak是个网络抓包工具,常用。但是在数据较大的网络环境中直接使用软件抓包会导致wireshark卡死。为什么呢 ?网卡瞬间...

windows下安装RabbitMQ

跳过舞,祝大家新年快乐哇!1、下载安装erlang因为rabbitmq是基于erlang实现的所以需要先安装erlang打开网址https://www.er...

NET CORE配置EF连接字符串。windows验证的连接字符串配置

在appsettings.json中配置好连接字符串{&quot;ConnectionStrings&quot;:{ &quot;BloggingDatabase&quot;:&quot;Server=(lo...

系统重装(一):安装制作windows原装系统U盘

Windows是美国微软公司研发的跨平台及设备应用的操作系统.xinXP已经停止更新,微软也将在2020年1月14日正式结束对Windows 7...

通过windows服务进行FTP与服务器之间文件的传输

这几天做了一个关于FTP与服务器之间文件互相传输的Windows服务,本地开发的时候非常顺利,很快就开发完成了,可是将服务部...

系统重装(二):安装windows系统

嗨,大家好!上一篇我们介绍了如何制作windows系统U盘,这一篇就来介绍一下如何安装。上一篇链接请点击:http://www.tnblog...

windows系统下如何查看及升级powershell到3.0版本

最近在学习.net core,用到了SQLServer.Data.EntityFrameworkCore框架,在根据数据库表生成对应实体类时提示必须先升级本机...

windows服务器 粘贴失败无法复制

windows服务器,复制粘贴失败,无法复制的问题重启rdpclip.exe进程即可

NotSupportedException: HTTP/2 over TLS is not supported on windows 7 due to missing

.net core grpc报错:NotSupportedException: HTTP/2 over TLS is not supported on Windows 7 due to missing ALPN suppor...

启动grpc报错:HTTP/2 over TLS is not supported on windows 7

.net core grpc报错:NotSupportedException: HTTP/2 over TLS is not supported on Windows 7 due to missing ALPN suppor...

c windows sdk科大讯飞语音合成

只是记录一下思路需要把c++的dll转换成c#用的dll可以用这种方式导入,需要把下载的sdk,放到bll