The iframe page and the vue parent page pass values to each other

1. The iframe page passes values ​​to the vue parent page

view

mounted() {
    
    
    let that = this;
    window.addEventListener("message", function (e) {
    
    
      console.log(e.data)
    });
  },

iframe

 window.parent.postMessage(code,"*");

2. The vue page passes values ​​to the iframe page

view

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

Guess you like

Origin blog.csdn.net/qq_44977477/article/details/108276718