(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>
相关推荐
excel24 分钟前
Node.js 断言与测试框架示例对比
前端
天蓝色的鱼鱼2 小时前
前端开发者的组件设计之痛:为什么我的组件总是难以维护?
前端·react.js
codingandsleeping2 小时前
使用orval自动拉取swagger文档并生成ts接口
前端·javascript
石金龙3 小时前
[译] Composition in CSS
前端·css
白水清风3 小时前
微前端学习记录(qiankun、wujie、micro-app)
前端·javascript·前端工程化
Ticnix3 小时前
函数封装实现Echarts多表渲染/叠加渲染
前端·echarts
用户22152044278003 小时前
new、原型和原型链浅析
前端·javascript
阿星做前端3 小时前
coze源码解读: space develop 页面
前端·javascript
叫我小窝吧3 小时前
Promise 的使用
前端·javascript
NBtab3 小时前
Vite + Vue3项目版本更新检查与页面自动刷新方案
前端