ChatList

ChatList is a component used to display a list of chat messages. It takes in an array of ChatMessage objects as the data prop and an optional type prop which can be either 'docs' or 'chat'. The component is memoized for better performance.

import { ChatList } from '@lobehub/ui/chat';

Default

CanisMinor

dayjs 如何使用 fromNow

😎

要使用 dayjs 的 fromNow 函数,需要先安装 dayjs 库并在代码中引入它。然后,可以使用以下语法来获取当前时间与给定时间之间的相对时间:

javascript
dayjs().fromNow(); // 获取当前时间的相对时间
dayjs('2021-05-01').fromNow(); // 获取给定时间的相对时间

第一个示例将返回类似于 "几秒前"、"一分钟前"、"2 天前" 的相对时间字符串,表示当前时间与调用 fromNow 方法时的时间差。第二个示例将返回给定时间与当前时间的相对时间字符串。

APIs

NameDescriptionTypeDefault
dataData of chat messages to be displayedChatMessage[](required)
enableHistoryCount--boolean--
historyCount--number--
loadingId--string--
groupNav--any--
loading--boolean--
onActionsClick点击操作按钮的回调函数(action:any,message:any)=>void--
onAvatarsClick--(role:any)=>any--
onMessageChange消息变化的回调函数(id:string,content:string)=>void--
renderActions--{}--
renderErrorMessages渲染错误消息的函数{}--
renderItems--{}--
renderMessages渲染消息的函数{}--
renderMessagesExtra渲染消息额外内容的函数{}--
showTitle是否显示聊天项的名称booleanfalse
text文本内容any--
type聊天列表的类型"docs"|"chat""chat"