使用ifram引入页面并传递参数

<template>
	<iframe id='myIframe' @load='postMsg' ref='myIframe' width='100%' height='100%' sre='http://www.baidu.come' frameborder='0' ></iframe>
</template>
created(){
	//在外面更改src的值
	document.getEelemntById('myIframe').src='http://www.albb.com'
	
	}
methods:{
	postMsg(){
		this.$refs.myIframe.contentwindow.postmessage({name:'ceshi'},'http://www.albb.com')
		}

	}
//另一个提供页面方,接受参数
<template>
	<div id='iframe' ><router-view></router-view><div>
</template>
export default{
		name:'iframe'
		methods:{
			receiveMsg(event){
				console.log(event)
			}
		},
		mounted(){
			window.addEventListener('msg',this.receiveMsg,false)
		}
	}
©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页