当iframe中src属性是一个远程地址,需要一定的加载时间,此时需要监听iframe加载完成事件
<iframe id="show-iframe" :src="lookUrl"/>
created(){
this.$nextTick(() => {
const iframe = document.getElementById('show-iframe')
if (!iframe.addEventListener) {
iframe.attachEvent('onload', this.iframeLoad)
}
// 当加载完成后,触发iframeLoad方法
iframe.addEventListener('load', this.iframeLoad, true)
})
}
methods:{
iframeLoad() {
// 此时iframe作为一个子组件,该方法用于通知父组件做一些事情,例如停止加载loading
this.$emit('iframeDone')
}
}