vue页面嵌套iframe页面传值、调用、首次传值获取不到、有缓存数据问题

在父组件中创建iframe

 


  <!-- iframe -->
      <!--  -->
    <el-dialog :visible.sync="dialogVisible" width="500px" @close="closeDialog" v-if="dialogVisible">
      <iframe id="iframe" ref="iframe" src="/static/test.html" width="100%" height="260px"></iframe>
    </el-dialog>

通过v-if的创建销毁dom,可以解决iframe页面缓存问题

 

父传子传值

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// 发起会话
    openif(infodata) {
      this.dialogVisible = true;
      var that = this;
      this.$nextTick(() => {<br>        //获取iframe元素
        const iframe = document.getElementById("iframe");
        iframe.onload = function (e) {
          //通过.contentWindow.postMessage(data,"*")向iframe子组件传值
          iframe.contentWindow.postMessage({
            
 
            // 暂时先写死
            'stationId': '69999', // 写死
            'loginId': '17999', // 坐席工号
            // 'dest': infodata.user_mobile, // 手机号+0
            'dest': "13455955635", // 手机号+0
            'username': infodata.ter_user_name ? infodata.ter_user_name : ""// 客户姓名
          }, "*");
        }
      });
    },
1
iframe.onload用来解决父传子首次传值获取不到数据的问题子组件接收传值
1
2
window.addEventListener("message", message => {
        console.log(message ); <br>})
1
 

  vue父页面调用ifarme子页面方法

1
 
1
2
3
4
5
// 监听用户关闭对话框,执行签出操作
   closeDialog() {
     const iframe = document.getElementById("iframe");
     iframe.contentWindow.jtapi_Loginout("17999", "69999");
   },
1
 

  

1
 

 

posted @   我太难了  阅读(863)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示