Skip to content

Bubble 气泡 / BubbleList 对话列表

Bubble 在线演示

Bubble — 聊天气泡

Prop类型默认值说明
placement'start' | 'end''start'气泡位置(左/右)
variant'filled' | 'outlined' | 'shadowed''filled'样式变体
shape'corner' | 'round''corner'气泡形状
avatarstringundefined头像 URL
avatarSizestring'32px'头像尺寸
headerstringundefined消息头(发送者名称)
contentstring''消息内容(支持 Markdown)
loadingbooleanfalse加载中骨架屏
typing{ step: number, interval: number }undefined打字机效果
footerstringundefined消息脚注(时间戳)

Slots:default(覆盖 content)/ header / avatar / footer

vue
<Bubble placement="end" header="我" content="你好" />
<Bubble placement="start" variant="outlined" content="AI 回复" />
<Bubble placement="start" loading content="" />

BubbleList — 对话列表(虚拟滚动)

Prop类型默认值说明
listBubbleListProps<T>[][]消息列表(泛型)
autoScrollbooleantrue新消息自动滚动到底部
maxHeightstring | numberundefined列表最大高度
gapnumber16消息间距(px)
loadingbooleanfalse加载更多历史消息
loadingTextstring'加载中...'加载提示文案
onScrollToTop() => voidundefined滚动到顶部回调(加载更多)

Slots:default{ item, index })/ footer(放 XSender)/ loading / empty

vue
<BubbleList :list="messages" max-height="300px">
  <template #default="{ item }">
    <div :class="['my-bubble', `my-bubble--${item.role}`]">
      <img :src="item.avatar" />
      <div class="my-content" v-html="item.content" />
    </div>
  </template>
  <template #footer>
    <XSender @submit="send" />
  </template>
</BubbleList>

泛型支持list 接受扩展 Bubble props 的自定义消息类型:

ts
interface MyMessage extends BubbleProps {
  id: number
  role: 'user' | 'ai'
}
const list: BubbleListProps<MyMessage>['list'] = [...]

内部机制:使用 virtua 虚拟滚动(仅渲染可见区域)、scrollIntoView 自动滚动、向上 50px 触发 onScrollToTop(加载历史)。