更新记录

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>

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

暂无用户评论。

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问