vue 中引入iframe,动态设置其src,遇到的一些小问题总结
1.重置其样式,去掉外框以及滚动条等
<iframe
id="myIframe"
ref="iframe_a"
:src="mySrc"
width="100%"
height="100%"
frameborder="no"
border="0"
marginwidth="0"
marginheight="0"
scrolling="no"
allowtransparency="yes"
/>
2.在mounted里也找不到iframe 的dom元素,于是用了很笨的办法去处理,希望路过的大佬可以指点一下,有好的办法教教我好吗??
export default {
data() {
return {
mySrc: '',
loading: true, // 如果正在加载,就会盖住展示内容
timer: null, // 第1个定时器
timer1: null // 第2个定时器
}
},
mounted() {
if (this.$refs && this.$refs['iframe_a']) {
this.setLoading(this.$refs['iframe_a'])
} else {
// console.log('延时加载第一次')
clearTimeout(this.timer1)
this.timer1 = setTimeout(() => {
this.setLoading(this.$refs['iframe_a'])
}, 500)
}
},
destroyed() {
this.timer = null
this.timer1 = null
},
methods: {
// 补坑函数1
setLoading(iframeDom) {
if (iframeDom) {
// console.log('找到元素了,执行iframeDom.onload')
const iframeD = document.getElementById('myIframeWebgl')
iframeD.onload = () => {
// console.log('加载完了-----------')
this.loading = false
}
iframeD.src = this.setRoute()
} else {
this.setTim()
}
},
// 补坑函数2
setTim() {
const iframeD = document.getElementById('myIframe')
clearTimeout(this.timer)
this.timer = setTimeout(() => {
// console.log('延时加载第----次')
this.setLoading(iframeD)
}, 200);
},
}
}
3.在此之前,加载完成的onload事件有时候不会触发,点击页面有时候没有反应,地址改了但是页面没有变动,于是解决如下:
问题在于: iframe的绑定地址的代码一定要放在onload下面,要不然就完了
如果使用原生来写,大概这样子
let myIframeDiv= document.querySelector('#myIframeDiv')
let iframe = document.createElement('iframe')
iframe.onload = () => {
console.log('这样子就没问题了')
}
iframe.src = this.src // 就是这一行代码,一定要注意哦
myIframeDiv.appendChild(iframe)
vue 中引入iframe,动态设置其src,遇到的一些小问题总结的更多相关文章
- vue中引入mintui、vux重构简单的APP项目
最近在学习vue时也了解到一些常用的UI组件,有用于PC的和用于移动端的.用于PC的有:Element(饿了么).iView等:用于移动端APP的有Vux.Mint UI(饿了么).Vant(有赞团队 ...
- 获取iframe子页面内容高度给iframe动态设置高度
<!DOCTYPE html><html> <head> <meta charset="UTF-8" /> <meta nam ...
- 【原创】如何在Android中为TextView动态设置drawableLeft等
如何在Android中为TextView动态设置drawableLeft等 两种方式: 方式1:手动设置固有边界 Drawable drawable = getResources().getD ...
- vue中引入babel步骤
vue中引入babel步骤 vue项目中普遍使用es6语法,但有时我们的项目需要兼容低版本浏览器,这时就需要引入babel插件,将es6转成es5. 1.安装babel-polyfill插件 npm ...
- vue中引入json数据,不用本地请求
1.我的项目结构,需要在Daily.vue中引入daily.js中的json数据 2.把json数据放入一个js文件中,用exports导出,vscode的json格式太严格了,很多数据,调了一个多小 ...
- vue中引入mui报Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them的错误
在vue中引入mui的js文件的时候,报如下的错误: 那是因为我们在用webpack打包项目时默认的是严格模式,我们把严格模式去掉就ok了 第一步:npm install babel-plugin-t ...
- vue中引入js,然后new js里的方法
阿里云Web播放器Web端使用SDK说明:https://help.aliyun.com/document_detail/51991.html?spm=5176.11065259.1996646101 ...
- vue中引入百度统计
vue作为单页面的,引入百度统计,需要注意不少. 一.基本的流量统计 在index.html 入口文件中引入百度统计生成的一连串代码: var _hmt = _hmt || []; (function ...
- vue中引入.svg图标,使用iconfont图标库
阿里巴巴的iconfont是一个很好的图标库,海量的素材可以快速满足开发人员日常对图标的诉求,我们采用symbol引用,官方介绍 创建SvgIcon组件 <template> <sv ...
- vue中引入swiper(vue中的滑块组件vue-awesome-swiper)
第一步安装 npm install vue-awesome-swiper --save 第二部在main.js中引入 import VueAwesomeSwiper from 'vue-awesome ...
随机推荐
- 微服务 Zipkin 链路追踪原理(图文详解)
一个看起来很简单的应用,可能需要数十或数百个服务来支撑,一个请求就要多次服务调用. 当请求变慢.或者不能使用时,我们是不知道是哪个后台服务引起的. 这时,我们使用 Zipkin 就能解决这个问题. 由 ...
- 浅尝 ECDHE 协议流程
前言 ECDHE 我之前是听都没听过, 但是新业务需要对前后端通信进行加密, 经过大佬推荐才知道有这个东西, 经过几天的学习和踩坑, 才大致明白其流程和使用方式. 过程坎坷, 好在最后还是成功运用到了 ...
- photoshop 2021 for mac安装教程,亲测可用!!!
小编分享下photoshop cc 2021 for mac 安装教程,适配M1芯片,让大家完美使用ps2021,畅享所有新功能Adobe Photoshop2021(简称PS) 新版本主要增加了Ne ...
- 基于FPGA的AES加解密IP
Programmable AES Encryption/ Decryption IP 可编程AES加解密IP 可编程AES加解密IP提供了加解密算法功能,兼容美国国家标准与技术研究院(NIST)发布的 ...
- 优化if、elif过多
优化if ,elif过多的场景 字典的成员运算,是判断字典的key 思路:把函数的内存地址存到字典当中 def login(): pass def scan(): pass def transf ...
- 通过Jenkins,执行远程服务器的自动化脚本
通过Jenkins,可自动执行写好的应用部署.自动化测试等的脚本工具,实现测试环境的应用自动定时更新.自动执行测试等. 1. 安装SSH插件 进入[系统管理]-[插件管理]-[可用插件],搜索Publ ...
- 【笔记】区间DP
记录一些基础的区间 \(\text{DP}\) 题. 0x00 AT_dp_n N - Slimes 最板的区间 \(\text{DP}\) . 记 \(f[i][j]\) 表示合并 \(i\sim ...
- perl 通过<<和文件句柄将数据写入到文件中去
可以通过文件句柄和<<运算符将文件内容写入到文件中去 #!usr/bin/perl -W use strict; use Spreadsheet::ParseExcel; use utf8 ...
- SpringBoot 06: springboot中使用redis
配置SpringBoot 创建SpringBoot项目时勾选Redis起步依赖 <dependency> <groupId>org.springframework.boot&l ...
- AtCoder Regular Contest 151补题
AtCoder Regular Contest 151 A. Equal Hamming Distances 简单题,注意下答案需要字典序最小即可 #include<bits/stdc++.h& ...