【发布时间】:2020-06-17 12:07:39
【问题描述】:
我的 Vue 应用程序包含嵌套在 Vuetify 对话框中的 iframe,我正在构建一个方法,该方法将通过 postMessage 将一些数据发送到 iframe,然后将弹出对话框,将显示带有所需数据的 iframe(在我的情况下 - 图像) 我的问题是在弹出对话框之前我无法指向 iframe 元素。
这是带有 iframe 的对话框:
<v-dialog
v-model="editBoardDialog"
>
<v-card>
<!-- HERE -->
<iframe id="ifrm" src="/ami.html" width="500" height="500"></iframe>
</v-card>
</v-dialog>
这些是通过 postMessage 将图像发送到 iframe 并弹出对话框的方法
//opens the dialog
openEditor() {
this.editBoardDialog = true
this.sendImageToIframe() //
},
//passing data to iframe
sendImageToIframe() {
let iframe = document.getElementById("ifrm").contentWindow; //return NULL... why?
//sends the image to the iframe
iframe.postMessage({action:"updateAll",data:this.board.editorDetails})
}
【问题讨论】:
-
对话框内容最初在 DOM 中不存在。只有在第一次打开时才会被注入。之后就可以继续查询了
标签: vue.js iframe vuetify.js postmessage