Skip to content

Streaming Response ​

Vue 已实现 · 还原验收 0/1 · 上游演示 · 固定版本源码

预览 ​

The release adds keyboard navigation, typed events, and source citations.

用法 ​

vue
<script setup lang="ts">
import { StreamingResponse } from 'beui-vue'
import { onBeforeUnmount, ref } from 'vue'
const answer = 'The release adds keyboard navigation, typed events, and source citations.'
const text = ref(answer)
const status = ref<'streaming' | 'complete'>('complete')
const sources = [{ id:'guide', title:'Vue accessibility guide', domain:'vuejs.org', url:'https://vuejs.org/guide/best-practices/accessibility.html' }]
let timer: ReturnType<typeof setInterval> | undefined
function stream() {
  clearInterval(timer)
  status.value = 'streaming'
  text.value = ''
  timer = setInterval(() => {
    text.value = answer.slice(0, text.value.length + 4)
    if (text.value === answer) { clearInterval(timer); status.value = 'complete' }
  }, 65)
}
onBeforeUnmount(() => clearInterval(timer))
</script>
<template><StreamingResponse :status="status" :copy-text="answer" :sources="sources" @retry="stream">{{ text }}</StreamingResponse></template>

API ​

默认插槽接收流式内容,status、announce、showActions 控制朗读和完成操作。可配置 copyText、@retry、sources、v-model:feedback 和 v-model:sources-open。

还原验收 ​

基于 beUI 的独立 Vue 移植,依 MIT 许可证分发。