vue呼叫巢狀iframe的方法
阿新 • • 發佈:2020-09-09
結合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.子元件方法名() }; }); }, }
relatedTopics.html
<script>
function 方法名(){
console.log('供父元件呼叫的方法')
}
</script>