清空iframe的内容

document.getElementById("web").contentWindow.document.body.innerText = "";

转载于:https://www.cnblogs.com/henuyuxiang/p/7383484.html

<template> <div class="container"> <div class="app-container"> <div v-if="isLoading" class="loading-indicator">加载中...</div> <div v-else class="iframe-container"> <iframe ref="myIframe" :src="'/iframe-api/UFM'" frameborder="0" scrolling="auto" ></iframe> </div> </div> </div> </template> <script> import axios from 'axios'; export default { name: 'CrossDomainLogin', data() { return { iframeSrc: '', isLoading: false, cancelToken: null, // 用于取消请求的令牌 routeWatcher: null // 路由监听器引用 }; }, mounted() { // this.initProcess(); // 监听路由变化 // this.routeWatcher = this.$watch('$route', (to, from) => { // if (from.path === this.$route.path) { // this.cleanup(); // } // }); }, beforeDestroy() { // 组件销毁前清理资源 this.cleanup(); // 移除路由监听 if (this.routeWatcher) { this.routeWatcher(); } }, methods: { async initProcess() { try { // 创建带凭证的axios实例 const http = axios.create({ withCredentials: true }); // 创建取消令牌 this.cancelToken = axios.CancelToken.source(); // 1. 发送登录请求 await this.requestLogin(http); // 2. 加载Iframe(确保组件未销毁) if (!this._isDestroyed) { this.iframeSrc = 'https://10.214.80.55:443'; } } catch (error) { if (!axios.isCancel(error)) { console.error('流程执行失败:', error.message); } } }, async requestLogin(http) { try { // 登录API的URL const loginUrl = 'https://10.214.80.55/dologin'; // 准备登录数据 const loginData = { httpd_username: 'admin', httpd_password: '123456' }; // 发送登录请求(带取消令牌) await http.post(loginUrl, loginData, { cancelToken: this.cancelToken.token }); console.log('登录成功,Cookie已获取'); } catch (error) { if (!axios.isCancel(error)) { console.error(`登录请求失败: ${error.message}`); throw new Error('登录请求失败'); } } }, handleIframeLoad() { // 确保组件未销毁 if (!this._isDestroyed) { this.isLoading = false; console.log('目标页面已加载'); } }, // 清理资源方法 cleanup() { // 1. 取消正在进行的请求 if (this.cancelToken) { this.cancelToken.cancel('路由已变更,取消请求'); this.cancelToken = null; } // 2. 清空iframe内容 if (this.$refs.myIframe) { this.$refs.myIframe.src = 'about:blank'; } // 3. 重置状态 this.isLoading = true; this.iframeSrc = ''; } } }; </script> <style scoped> /* 样式保持不变 */ iframe { width: 100%; height: 100vh; border: none; border-radius: 10px; } </style> 把这个改为UFM UFM 要经过两个接口,怎么在devServer 中配置
最新发布
07-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值