在vue中监听信息
<iframe id="projectIframe" frameborder="0" scrolling="no" name="proframe" src="" @load="iframeLoad"></iframe>
//当iframe执行load事件时,去监听iframe传来的消息
iframeLoad(){
window.addEventListener("message", this.handleMessage);
},
//获取iframe传过来的信息
handleMessage(e){
//e为传过来的信息
conslose.log(e)
}
传递消息
在iframe中如何将所需要的数据传递过来,需要用到postMessage,他是可以跨域的
window.parent.postMessage(data, '*');