(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>
相关推荐
toooooop81 天前
Vuex 中 state、mutations 和 actions 的原理和写法
前端·javascript·uni-app
y***86691 天前
前端CSS-in-JS方案
前端·javascript·css
暖木生晖1 天前
APIs之WEB API的基本认知是什么?
前端·dom·dom树·web apis
华仔啊1 天前
你真的懂递归吗?没那么复杂,但也没那么简单
前端·javascript
火星数据-Tina1 天前
低成本搭建体育数据中台:一套 API 如何同时支撑比分网与 App?
java·前端·websocket
yddddddy1 天前
深入浅出前端路由:从概念到实战
前端
专业抄代码选手1 天前
【Leetcode】1930. 长度为 3 的不同回文子序列
javascript·算法·面试
林_xi1 天前
uniapp使用@uni-ku/root插件实现全局组件
前端·uni-app
一个处女座的程序猿O(∩_∩)O1 天前
UniApp 生命周期全解析:从应用到页面,再到组件的完美协奏曲
前端·uni-app
龙颜1 天前
从0-1封装一个React组件
前端·react.js