(vue)将dify和ragflow页面嵌入到vue3项目

(vue)将dify和ragflow页面嵌入到vue3项目


dify:

ragflow:


代码:

bash 复制代码
<template>
  <div class="dify-container">
    <iframe
      :src="`https://dify.dev.tudb.work/apps`" //ragflow地址:https://ragflow19.prod.tudb.work/
      frameborder="0"
      width="100%"
      :height="data.height"
    ></iframe>
  </div>
</template>

<script setup>
import { onMounted, onUnmounted, reactive } from 'vue';
const data = reactive({
  height: 0,
  email: '...@admin.com',
  password: '...@2025'
})

onMounted(() => {
  const dom = document.querySelector('.app-main');
  const height = dom ? dom.offsetHeight : 0;
  data.height = height;

  window.addEventListener('message', handleMessage);
});

onUnmounted(() => {
  window.removeEventListener('message', handleMessage);
});

const handleMessage = (event) => {
  const { isLoad, isLogin, isFailed } = event.data;
  if(isLoad){
    postToIframe();
    return
  }

  if(isLogin){//登录成功
    console.log('登录成功')
    return 
  }

  if(isFailed){//登录失败
    return
    console.log('登录失败')
  }
}

const postToIframe = () => {
  const iFrame = document.querySelector('iframe')
  if (iFrame) {
    iFrame.contentWindow?.postMessage({
      email: data.email,
      password: data.password,
    }, '*')
  }
}
</script>

<style lang="scss" scoped>
.dify-container {
  height: 100%;
}
</style>
相关推荐
山河木马9 分钟前
矩阵专题3-怎么创建投影矩阵(uProjectionMatrix)
javascript·webgl·计算机图形学
天蓝色的鱼鱼1 小时前
关于 CSS 你可能不知道的属性,但关键时刻很有用
前端·css
泯泷2 小时前
第 2 篇:设计第一套字节码:Opcode、Instruction 与 Constant Pool
前端·javascript·安全
妙码生花2 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(十五):优化细节、网络请求封装
前端·后端·ai编程
泯泷2 小时前
第 1 篇:从 1 + 2 开始:亲手写出第一台 JSVM
前端·javascript·安全
团团崽_七分甜2 小时前
Spring Boot 核心知识点总结
前端
lichenyang4532 小时前
从一个按钮开始,理解 ASCF 框架到底在做什么
前端
古夕3 小时前
第三方 SSO 接入实践:redirect_uri 编码、回调一致性与跨项目联调
前端·vue.js
朦胧之3 小时前
页面白屏卡住排查方法
前端·javascript
用户593608741403 小时前
Playwright 黑魔法:用 ClipboardEvent 绕过 React 富文本编辑器
前端