iframe页面与vue父页面相互传值

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)
	}  

猜你喜欢

转载自blog.csdn.net/qq_44977477/article/details/108276718