这是使用contentWindow调用本地HTML方法的一篇博客
调用vue嵌套本地HTML的坑
当我使用button获取时没有问题
iframeValue(){
var oIframe = document.getElementById('show-iframe');
console.log(oIframe.contentWindow.document)
console.log(oIframe.contentWindow.document.getElementById("loginip"))
}
但是如果放在钩子函数moutend中
mounted() {
console.log("============")
var oIframe = document.getElementById("show-iframe");
//const deviceWidth = document.documentElement.clientWidth;
const deviceHeight = document.documentElement.clientHeight;
// oIframe.style.width = deviceWidth + 'px';
console.log(deviceHeight );
oIframe.style.height = deviceHeight * 0.97 + 'px';
console.log(oIframe.style.height);
oIframe.onload = function() {
console.log("=====222=======")
console.log("contentWindow", oIframe.contentWindow.document);
console.log("contentWindow1", oIframe.contentWindow.document.getElementById("loginip"));
}
必须加上onload方法 或者使用window.onload