vue調用嵌套iframe的方法


結合elementui中的drawer,在第一次被打開之前是不會渲染dom的,因此需要等渲染完成才獲取iframe組件
vue:

<template>
<el-drawer :with-header="false" :visible.sync="drawer" :before-close="handleClose" class="helpHelperPop" ref="drawer" size="200px">
     <div class="height100">
         <iframe src="./assisHelpHtml/relatedTopics.html" frameborder="0" class="height100" style="width: 100%;" ref="helpNestedFrame" id="helpNestedFrame"></iframe>
     </div>
</el-drawer>
</template>

methods: {
    closeHelp() {
      this.drawer = true;
      this.$nextTick(() => {
        this.$refs.helpNestedFrame.onload = () => {
          this.$refs.helpNestedFrame.contentWindow.子組件方法名()
        };
      });
    },
}

iframe的src中需要添加下面的方法:

<script>
      function 子組件方法名(){
            console.log('供父組件調用的方法')
      }
</script>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM