1.html文件
<iframe src="https://guides.github.com" id="ifra" frameborder="0"></iframe>
2.vue 生命周期的 mounted 阶段
mounted () {
var _this = this
const iframe = document.querySelector('#ifra')
// 处理兼容行问题
if (iframe.attachEvent) {
iframe.attachEvent('onload', function () {
// iframe加载完毕以后执行操作
console.log('iframe已加载完毕')
})
} else {
iframe.onload = function () {
// iframe加载完毕以后执行操作
console.log('iframe已加载完毕')
}
}
}
IE 支持 iframe 的 onload 事件,不过是隐形的,需要通过 attachEvent 来注册。