一.html文件中引入的iframe標籤html
1.在父html中調用子iframe html 中的事件vue
經過contentwindow屬性this
document.getElementById("myiframe").contentWindow.myfunc()
其中 myiframe 爲當前的iframe的id, myfunc爲iframe html中的事件spa
2.在iframe html 中調用父HTML 的方法code
parent.func()
二.vue頁面中引入的iframe標籤htm
1.在vue組件中調用iframe html 中的事件blog
self.$refs.iframe.contentWindow.myfunc()
2.在iframe html 中調用vue methods 事件
(1).在vue中設置標識id 並將方法暴露在window中get
export default{ data(){ return { vueid:"myid" } }, methods:{ changeNodeMsg(){ alert(0) } }, created(){ let self = this window[this.vueid] = ()=>{ self.changeNodeMsg() } }
在iframe html中使用iframe
window.parent["myid"]()