使用vue巢狀本地HTML
阿新 • • 發佈:2020-12-10
技術標籤:vue
這是使用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