1. 程式人生 > 其它 >使用vue巢狀本地HTML

使用vue巢狀本地HTML

技術標籤: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