学无先后,达者为师

网站首页 Vue 正文

vue判断iframe是否加载完毕

作者:阳光6号 更新时间: 2022-03-04 Vue

html

<main>
  <img v-show="!completeLoad" src="../images/loading.gif"/>
  <iframe v-show="completeLoad" :src="url" width="100%" id="license_iframe" height="100%"></iframe>
</main>

js

mounted () {
	var _this = this
	const iframe = document.querySelector('#license_iframe')
	// 处理兼容行问题
	if (iframe.attachEvent) {
		iframe.attachEvent('onload', function () {
			console.log('iframe已加载完毕')
			_this.completeLoad = true;
        })
    } else {
        iframe.onload = function () {
            console.log('iframe已加载完毕')
            _this.completeLoad = true;
        }
    }
}

原文链接:https://blog.csdn.net/weixin_37744901/article/details/108492063

栏目分类
最近更新