废话不说,直接上代码。
1、父页面代码,监听子页面消息:window.addEventListener
<template>
<iframe v-if="iframeURL" :src="iframeURL" ref="iframe" width="100%" height="810" frameborder="0" scrolling="yes" @opened="handleOpened"></iframe>
</template>
<script>
import {
addDynamicRoute } from '@/router'
export default {
data () {
return {
iframeURL: null,
menuId: '',
href: '',
iframeWin: {
}
}
},
mounted () {
/** 监听子页面传递过来的消息 **/
/** this.handleMessage,表示监听到消息后的处理事件 **/
window.addEventListener('message', this.handleMessage)
},
created () {
this.menuId = this.$route.meta.menuId || ''
this.href = this.$route.params.href || ''
this.init()
},
methods: {
handleOpened