ChatPrompt 组件渲染一个 `
使用 `variant` 属性来改变提示框的样式。默认为 `outline`。
<template> <UChatPrompt variant="soft" /> </template>
使用 AI SDK v5 中的 `Chat` 类与 ChatPrompt 组件结合使用,可在页面内显示聊天提示框。
在出现错误时,将 `input` 属性与 `error` 属性一起传递,以禁用文本区域。
<script setup lang="ts"> import { Chat } from '@ai-sdk/vue' import { getTextFromMessage } from '@nuxt/ui/utils/ai' const input = ref('') const chat = new Chat({ onError(error) { console.error('Chat error:', error) } }) const handleSubmit = (e: Event) => { e.preventDefault() chat.sendMessage({ text: input.value }) input.value = '' } </script> <template> <UDashboardPanel> <template #body> <UContainer> <UChatMessages :messages="chat.messages" :status="chat.status"> <template #content="{ message }"> <MDC :value="getTextFromMessage(message)" :cache-key="message.id" unwrap="p" /> </template> </UChatMessages> </UContainer> </template> <template #footer> <UContainer> <UChatPrompt v-model="input" :error="chat.error" @submit="handleSubmit"> <UChatPromptSubmit :status="chat.status" @stop="chat.stop" @reload="chat.regenerate" /> </UChatPrompt> </UContainer> </template> </UDashboardPanel> </template>
你也可以将其用作聊天界面的起点。
<script setup lang="ts"> import { Chat } from '@ai-sdk/vue' const input = ref('') const chat = new Chat() async function onSubmit() { const userInput = input.value input.value = '' chat.sendMessage({ text: userInput }) // Navigate to chat page after first message if (chat.messages.length === 1) { await navigateTo('/chat') } } </script> <template> <UDashboardPanel> <template #body> <UContainer> <h1>How can I help you today?</h1> <UChatPrompt v-model="input" @submit="onSubmit"> <UChatPromptSubmit :status="chat.status" /> </UChatPrompt> </UContainer> </template> </UDashboardPanel> </template>
as
'form'
any
此组件应渲染为的元素或组件。
placeholder
t('chatPrompt.placeholder')
string
文本区域的占位符文本。
autofocus
true
boolean
自动调整大小
行数
1
number
variant
'outline'
"outline" | "soft" | "subtle" | "naked"
error
错误
loading
当为 true 时,将显示加载图标。
loadingIcon
appConfig.ui.icons.loading
字符串 | 对象
当 loading prop 为 true 时显示的图标。
图标
根据 leading 和 trailing 属性显示图标。
leading
trailing
avatar
AvatarProps
在左侧显示头像。
作为?: 任何
此组件应渲染为的元素或组件。默认为 'span'。
'span'
src?: string
alt?: string
图标?: 字符串 | 对象
text?: string
size?: "3xs" | "2xs" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl"
默认为 'md'。
'md'
chip?: boolean | ChipProps
class?: any
style?: any
ui?:{ root?: ClassNameValue; image?: ClassNameValue; fallback?: ClassNameValue; icon?: ClassNameValue; }
autofocusDelay
自动调整大小延迟
最大行数
modelValue
''
ui
{ root?: ClassNameValue; header?: ClassNameValue; body?: ClassNameValue; footer?: ClassNameValue; base?: ClassNameValue; } &{ root?: ClassNameValue; base?: ClassNameValue; leading?: ClassNameValue; leadingIcon?: ClassNameValue; leadingAvatar?: ClassNameValue; leadingAvatarSize?: ClassNameValue; trailing?: ClassNameValue; trailingIcon?: ClassNameValue; }
root?: ClassNameValue
header?: ClassNameValue
body?: ClassNameValue
footer?: ClassNameValue
base?: ClassNameValue
leading?: ClassNameValue
leadingIcon?:ClassNameValue
leadingAvatar?:ClassNameValue
leadingAvatarSize?:ClassNameValue
trailing?:ClassNameValue
trailingIcon?:ClassNameValue
页头
{}
页脚
前置
default
尾部
close
[event: Event]
submit
update:modelValue
[value: string]
export default defineAppConfig({ ui: { chatPrompt: { slots: { root: 'relative flex flex-col items-stretch gap-2 px-2.5 py-2 w-full rounded-lg backdrop-blur', header: 'flex items-center gap-1.5', body: 'items-start', footer: 'flex items-center justify-between gap-1.5', base: 'text-base/5' }, variants: { variant: { outline: { root: 'bg-default/75 ring ring-default' }, soft: { root: 'bg-elevated/50' }, subtle: { root: 'bg-elevated/50 ring ring-default' }, naked: { root: '' } } }, defaultVariants: { variant: 'outline' } } } })
import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import ui from '@nuxt/ui/vite' export default defineConfig({ plugins: [ vue(), ui({ ui: { chatPrompt: { slots: { root: 'relative flex flex-col items-stretch gap-2 px-2.5 py-2 w-full rounded-lg backdrop-blur', header: 'flex items-center gap-1.5', body: 'items-start', footer: 'flex items-center justify-between gap-1.5', base: 'text-base/5' }, variants: { variant: { outline: { root: 'bg-default/75 ring ring-default' }, soft: { root: 'bg-elevated/50' }, subtle: { root: 'bg-elevated/50 ring ring-default' }, naked: { root: '' } } }, defaultVariants: { variant: 'outline' } } } }) ] })
3173b— fix: proxySlots 响应性 (#4969)
3173b
5cb65— 特性:导入 @nuxt/ui-pro 组件
5cb65
@nuxt/ui-pro
ChatPalette
用于在覆盖层中创建聊天机器人的聊天面板。
ChatPromptSubmit
用于提交聊天提示的按钮,具有自动状态处理功能。
本页内容
社区