iframe跨域访问+vue+Elment-ui

首先,
1、在html中先写一个iframe标签
<iframe :src="src2" scrolling="no" ref="iframe2" frameborder="0" class="frame" style="width:100%;height:600px">
2、定义src访问地址
export default {

src2:'http://localhost:8080/#/aaa'+'?id=123' ,

}

3、用postMessage传值,this是当前页面,$nextTick是先等页面加载完以后在加载, postMessage第一个参数是你要传的值,第二个参数是你要访问的IP地址和端口号

 this.$nextTick(() => {
            this.$refs.iframe2.contentWindow.postMessage(row.id, '*');

          });

4、在aaa页面写

window.addEventListener('message',this.handleMessage,false)

5、创建handleMessage方法

 handleMessage (event) {
          // console.log(111212312312);
          // console.log(event);
          console.log(event.data);//这个是iframe传的值
        this.data = event.data;
        if (this.data.type==="webpackOk") {
          return
        }else {
          this.init();//写自己要查的方法
        }

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你想了解关于Vue和Element UI如何使用iframe吗?你可以在Vue项目中使用Element UI组件来嵌入一个iframe。首先,你需要安装并引入Element UI库。然后,你可以使用Element UI的`el-dialog`组件来创建一个包含iframe的对话框。 首先,确保你已经在Vue项目中安装了Element UI。如果没有,请按照官方文档进行安装。 接下来,在你想要使用iframe的组件中,导入`el-dialog`和需要显示的页面的URL: ```javascript <template> <div> <el-button @click="openDialog">打开页面</el-button> <el-dialog :visible.sync="dialogVisible" width="800px" height="600px"> <iframe :src="iframeUrl" width="100%" height="100%"></iframe> </el-dialog> </div> </template> <script> import { ElDialog } from 'element-ui'; export default { components: { ElDialog }, data() { return { dialogVisible: false, iframeUrl: 'https://example.com' // 替换为你想要显示的页面的URL }; }, methods: { openDialog() { this.dialogVisible = true; } } }; </script> ``` 上述示例中,我们创建了一个按钮,点击按钮将会打开一个包含iframe的对话框。对话框使用`el-dialog`组件,并使用`:visible.sync`来控制对话框的显示和隐藏。 iframe的URL是通过`iframeUrl`属性指定的。你可以将其替换为你想要显示的页面的URL。 通过这种方式,你可以在Vue项目中使用Element UI来嵌入iframe并显示其他页面的内容。记得根据自己的需求进行适当的调整和样式修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值