【Vue】 在 vue 中使用 iframe 挂载 html 文件

文章目录

  1. 首先需要将要挂载的html文件放到public 文件夹中

在这里插入图片描述

  1. 路径的引用形式
<iframe ref="sheet" src="/luckysheet.html" width="100%" height="100%"></iframe>
  1. 通过绑定 ref 获取到 iframe,data为我需要传递的数据,通过 iframes.postMessage 的方法进行传递。
sentMsgSheet(data) {
    
    
	const sheetWindow = this.$refs.sheet.contentWindow;
	if (sheetWindow) {
    
    
		sheetWindow.postMessage(data, '*');
	}
}
sentMsgSheet([]);
  1. postMessage 通信具体用法请参考:https://blog.csdn.net/qq_45677671/article/details/128238860

猜你喜欢

转载自blog.csdn.net/qq_45677671/article/details/131721230