父页面
<iframe src="http://localhost:8080/index.html" id="vrId"></iframe>
父页面接收子页面的参数
mounted(){
window.addEventListener('message', function(e){
console.log(e.data)
})
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
iframe页面
created(){
top.postMessage(需要传递给父页面的参数)
}
注意:如果使用window.postMessage() 可能会出现 Failed to execute 'postMessage' on 'DOMWindow' 报错
其实 top就是指向iframe最顶层的窗口,建议是用 top.postMessage()即可