vue3 销毁iframe

时间: 2023-09-18 10:08:42 浏览: 115
在Vue 3中销毁iframe的方法类似于Vue 2。你可以通过获取iframe的window对象,然后调用销毁方法来实现。你可以使用以下代码来销毁iframe: ``` const iframe = document.getElementById("ifm__device_book_search_warehouse"); const iframeWindow = iframe.contentWindow; if (iframeWindow && iframeWindow.app) { iframeWindow.app.$destroy(true); } ``` 这段代码首先获取iframe元素的window对象,然后检查是否存在`app`实例。如果存在,就调用其`$destroy`方法来销毁Vue实例。这样可以确保在关闭vue模块的界面时,能够正确地销毁iframe中的Vue实例。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Vue中对iframe实现keep alive无刷新的方法](https://download.csdn.net/download/weixin_38553478/14822462)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [记在老旧项目中销毁vue生命周期#iframe](https://blog.csdn.net/weixin_42676205/article/details/122001876)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

相关推荐

// var agent, password, mode, phoneId //登录所需参数 // window.onload = function () { // init(); // }; //初始化电话条 function init() { var iframe = document.createElement('iframe'); iframe.name = "uinCall"; iframe.id = "uinCall"; iframe.ref = "uinCall"; iframe.allow = "microphone"; iframe.src = "https://ykf.uincall.com/telephonebarplugin/index.html"; // iframe.src = "https://ceshi.uincall.com/telephonebarplugin/index.html"; var telephoneBar = document.getElementById("telephoneBar"); if (telephoneBar) { telephoneBar.appendChild(iframe); var uinCall = document.getElementById("uinCall"); console.log('@@@-', uinCall); iframe.style.width = telephoneBar.getAttribute("data-width"); iframe.style.height = telephoneBar.getAttribute("data-height"); iframe.style.border = 0; } } //打印来自电话条内的抛出事件 window.addEventListener('message', function (e) { // console.log('@EchoData','message>>',e) console.info(e); if (e.data) { try { var resData = JSON.parse(e.data); // 动态修改iframe的高度 if (resData && resData.key && resData.key === 'changeCallHistoryState') { var telephoneBar = document.getElementById("telephoneBar"); var uinCall = document.getElementById("uinCall"); var frameHeight = telephoneBar.getAttribute("data-height"); if (resData.data) { // 显示 var heightConfig = parseInt(frameHeight); uinCall.style.height = (!heightConfig || heightConfig < 310) ? '310px' : heightConfig + 'px'; } else { uinCall.style.height = frameHeight; } } } catch (err) { console.info(e); } } }); //高级话务 function telephoneFunction(data) { let uincall = document.getElementById('uinCall'); if (uincall) { uincall.contentWindow.postMessage(data, '*'); } else { init(); uincall = document.getElementById('uinCall'); if (uincall) { setTimeout(() => { uincall.contentWindow.postMessage(data, '*'); }, 500); } } } 用vue优化代码编程

/* * @Author: LinLong * @LastEditors: LinLong * @Description: 上课进度上传 */ import { ref, onMounted, onUnmounted } from 'vue' import { getItem, setItem } from '@/hooks' import { uselearningProgress } from '@/stores' import { updatedLearningProgress } from '@/apiList/learningProgress' const learningProgressStore = uselearningProgress() //学习进度仓库 const currentProgressFile = ref(null) //当前学习进度文件 const heartbeatTime = 30 * 1000 //30秒 let timer = null //时间函数 export function useClassProgress(onBeforeRouteLeave) { //从仓库获取用户点击的课程->项目->任务->文件 learningProgressStore.$subscribe((mutation, state) => { const { currentProgress } = state // console.log('%c--currentProgress-->', 'background:#18C36E;color:#3F4040;', currentProgress) currentProgressFile.value = { classId: currentProgress.classId, courseId: currentProgress.courseId, courseId_text: currentProgress.courseId_text, projectId: currentProgress.pid == 0 ? currentProgress.id : currentProgress.pid, // projectId: currentProgress.id, taskId: currentProgress.pid == 0 ? null : currentProgress.id, pid_text: currentProgress.pid_text, name: currentProgress.name, file: currentProgress.url, userId: getItem('userInfo').id, } // console.log('%c-----state 学习进度------->', 'background:#18C36E;color:#3F4040;', currentProgress) }) //生命周期页面挂载完毕 onMounted(() => { //接收iframe 异步框架消息 window.addEventListener('message', (e) => { if (e.origin.includes('8013')) { const data = e.data setItem('postMessage', data) // console.log('%c-----监听postMessage子级------->', 'background:#18C36E;color:#3F4040;', JSON.parse(data)) } }) //浏览器tab标签切换或最小化事件设置暂停提交 上课记录 document.addEventListener('visibilitychange', () => { if (document.visibilityState === 'hidden') { timer ? clearTimeout(timer) : (timer = null) //清除定时器 } else if (document.visibilityState === 'visible') { timer ? clearTimeout(timer) : (timer = null) //先清除一次定时器 sendMessage() //继续发送学习进度 } }) //发送统计信息至后端 sendMessage() function sendMessage() { console.log('%c---对方水电费水电费水电费->', 'background:#18C36E;color:#3F4040;') timer ? clearTimeout(timer) : (timer = false) //先清除一次定时器 timer = setTimeout(() => { const sendData = { ...getItem('postMessage'), ...currentProgressFile.value, } // console.log('%c------准备发送的信息sendData------>', 'background:#18C36E;color:#3F4040;', sendData) updatedLearningProgress(sendData).then((res) => { if (res.success) sendMessage() }) }, heartbeatTime) //heartbeatTime } }) //生命周期页面销毁之前 onUnmounted(() => { clearTimeout(timer) // //路由离开 // onBeforeRouteLeave(() => { // clearTimeout(timer) // }) }) }

最新推荐

recommend-type

在vue中实现嵌套页面(iframe)

主要介绍了在vue中实现嵌套页面(iframe),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
recommend-type

VUE 3D轮播图封装实现方法

主要为大家详细介绍了VUE 3D轮播图封装实现方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

Vue中关闭弹窗组件时销毁并隐藏操作

主要介绍了Vue中关闭弹窗组件时销毁并隐藏操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
recommend-type

解决vuecli3中img src 的引入问题

主要介绍了解决vuecli3中img src 的引入问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
recommend-type

vue组件中使用iframe元素的示例代码

本篇文章主要介绍了vue组件中使用iframe元素的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

用 Python 画一个可以动的爱心

好的,我可以帮助您使用Python来绘制一个动态的爱心。您可以使用turtle库来实现。以下是实现代码: ```python import turtle import math # 设置画布和画笔 canvas = turtle.Screen() canvas.bgcolor("black") pencil = turtle.Turtle() pencil.speed(0) pencil.color("red", "pink") pencil.pensize(3) # 定义爱心函数 def draw_love(heart_size, x_offset=0, y_offset=0):
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。