更新记录
1.0.0(2025-06-02)
下载此版本
首次上传
平台兼容性
uni-app(4.66)
Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
√ |
- |
- |
- |
- |
- |
- |
- |
- |
微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
快应用-华为 |
快应用-联盟 |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
uni-app x(4.66)
Chrome |
Safari |
Android |
iOS |
鸿蒙 |
微信小程序 |
- |
- |
- |
- |
- |
- |
属性说明
属性名 |
类型 |
默认值 |
说明 |
title |
String |
无 |
聊天窗口标题(显示在顶部栏) |
userAvatar |
String |
无 |
当前用户头像 URL,不传则使用默认随机头像 |
initialMessages |
String |
无 |
初始消息列表,格式为 [{id, type, content, contentType, time}] |
消息对象格式
复制代码{
id: Number, // 消息唯一标识(如时间戳)
type: 'user' | 'other', // 消息类型(用户或对方)
content: String, // 消息内容(文本或图片URL)
contentType: 'text' | 'image', // 内容类型
time: Date, // 消息时间
avatar?: String // 对方头像URL(可选,默认使用defaultAvatar)
}
事件(可触发的方法)
事件名 |
触发时机 |
返回值 |
说明 |
@send |
发送消息时 |
消息对象 |
向外传递用户发送的消息 |
基础用法
复制代码<template>
<view class="container">
<naiya-chat
:title="chatTitle"
:userAvatar="userInfo.avatar"
:initialMessages="messageList"
@send="handleSendMessage" ></naiya-chat>
</view>
</template>
<script>
export default {
data() {
return {
chatTitle: '客服聊天',
userInfo: {
avatar: 'https://picsum.photos/200/200?random=2'
},
messageList: [
{
id: 1,
type: 'other',
content: '你好!有什么可以帮助你的吗?',
contentType: 'text',
time: new Date()
}
]
}
},
methods: {
handleSendMessage(message) {
console.log('发送消息:', message);
}
}
}
</script>
<style>
.container {
height: 100vh;
}
</style>