Hi FE !
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
  • 通过 md 展示流式接口返回

通过 md 展示流式接口返回

<script setup>
import { askApi } from "@/common/stream.js";

import textToMd from "./common/textToMd.vue";

const robotText = ref({
  text: "hello world",
});

const sendGPT = (content) => {
  isAnalyzing.value = true;
  stopRequest.value = askApi(
    { ...content },
    {
      change: (e) => {
        let { id, name, data, stop, type } = e;
        robotText.text += data;
      },
      end: () => {},
      error: (err, isFullText, needSpecial = false) => {
        if (!err.toString().includes("user aborted")) {
          let msg = "";
          if (isFullText) {
            msg = err;
          } else {
            msg = "网络异常,请稍后重试";
          }
          // reject(msg);
        } else {
          // reject();
        }
      },
    }
  );
};
</script>

<template>
  <textToMd :isMark="true" :value="robotText.text" />
</template>
Edit this page
最近更新: 2025/12/2 01:46
Contributors: qdleader
qdleader
本站总访问量 129823次 | 本站访客数 12人