1.iframe页面向vue父页面传值
vue
mounted() {
let that = this;
window.addEventListener("message", function (e) {
console.log(e.data)
});
},
iframe
window.parent.postMessage(code,"*");
2.vue页面向iframe页面传值
vue
mounted(){
this.iframe = this.$refs.iframe
this.iframeWindow = this.iframe.contentWindow
let message = 1
this.iframeWindow.postMessage(message, '*')
}
iframe
window.addEventListener('message', function (e) {
console.log(e.data)
}