开发环境要求
Vue 3
TypeScript
sass(sass-loader 版本 ≤ 10.1.1)
node(12.13.0 ≤ node 版本 ≤ 17.0.0, 推荐使用 Node.js 官方 LTS 版本 16.17.0)
npm(版本请与 node 版本匹配)
TUIKit 源码集成
步骤1:创建项目
TUIKit 支持使用 webpack 或 vite 创建项目工程,配置 Vue3 + TypeScript + sass。以下是几种项目工程搭建示例:
使用 vue-cli 方式创建项目, 配置 Vue3 + TypeScript + sass。
如果您尚未安装 vue-cli ,可以在 terminal 或 cmd 中采用如下方式进行安装:
npm install -g @vue/cli@4.5.0 sass sass-loader@10.1.1
通过 vue-cli 创建项目,并选择下图中所选配置项。
vue create chat-example
创建项目完成后,切换到项目所在目录
cd chat-example
使用 create-vue 方式创建项目,配置 Vue3 + TypeScript + sass。
确保你安装了最新 LTS 版本的 Node.js,然后在命令行中运行以下命令安装并执行 create-vue:
npm init vue@latest
按照如下选择进行配置:
创建项目完成后,切换到项目所在目录,安装项目对应依赖以及 TUIKit 所需环境( TypeScript、sass、sass-loader)
# 切换至项目所在目录cd chat-example# 安装项目依赖npm install# 安装 TUIKit 所需环境npm install typescript sass sass-loader -D
使用 vite 方式创建项目,配置 Vue3 + TypeScript + sass。
npm create vite@latest
按照如下选择进行配置:
创建项目完成后,切换到项目所在目录,安装项目对应依赖以及 TUIKit 所需环境( TypeScript、sass、sass-loader)
# 切换至项目所在目录cd chat-example# 安装项目依赖npm install# 安装 TUIKit 所需环境npm install typescript sass sass-loader -D
步骤2:下载 TUIKit 组件
npm i @tencentcloud/chat-uikit-vuemkdir -p ./src/TUIKit && cp -r ./node_modules/@tencentcloud/chat-uikit-vue/ ./src/TUIKit
npm i @tencentcloud/chat-uikit-vue
xcopy .\\node_modules\\@tencentcloud\\chat-uikit-vue .\\src\\TUIKit /i /e
成功后目录结构如图所示:
步骤3:引入 TUIKit 组件
在 main.ts 中,引入 TUIKit,并注册到 Vue 项目实例中:
import { createApp } from 'vue';import App from './App.vue';import { TUIComponents, TUICore, genTestUserSig } from './TUIKit';// import TUICallKitimport { TUICallKit } from '@tencentcloud/call-uikit-vue';const SDKAppID = 0; // Your SDKAppIDconst secretKey = ''; //Your secretKeyconst userID = ''; // User ID// init TUIKitconst TUIKit = TUICore.init({SDKAppID,});// TUIKit add TUIComponentsTUIKit.use(TUIComponents);// TUIKit add TUICallKitTUIKit.use(TUICallKit);// login TUIKitTUIKit.login({userID: userID,userSig: genTestUserSig({SDKAppID,secretKey,userID,}).userSig, // The password with which the user logs in to IM. It is the ciphertext generated by encrypting information such as userID.For the detailed generation method, see Generating UserSig});createApp(App).use(TUIKit).mount('#app');
步骤4: 获取 SDKAppID 、密钥与 userID
设置 main.ts 文件示例代码中的相关参数 SDKAppID、secretKey 以及 userID ,其中 SDKAppID 和密钥等信息,可通过 即时通信 IM 控制台 获取,单击目标应用卡片,进入应用的基础配置页面。例如:

userID 信息,可通过 即时通信 IM 控制台 进行创建和获取,单击目标应用卡片,进入应用的账号管理页面,即可创建账号并获取 userID。例如:



步骤5:调用 TUIKit 组件
在需要展示的页面,调用 TUIKit 的组件即可使用。
例如:在 App.vue 页面中,使用 TUIConversation、TUIChat、TUISearch、TUICallKit 快速搭建聊天界面(以下示例代码同时支持 Web 端与 H5 端)。
<template><div class="home-TUIKit-main"><div :class="env?.isH5 ? 'conversation-h5' : 'conversation'" v-show="!env?.isH5 || currentModel === 'conversation'"><TUISearch class="search" /><TUIConversation @current="handleCurrentConversation" /></div><div class="chat" v-show="!env?.isH5 || currentModel === 'message'"><TUIChat><h1>欢迎使用腾讯云即时通信IM</h1></TUIChat></div><Drag :show="showCall" class="callkit-drag-container" domClassName="callkit-drag-container"><!-- TUICallKit 组件:通话 UI 组件主体 --><TUICallKit:allowedMinimized="true":allowedFullScreen="false":beforeCalling="beforeCalling":afterCalling="afterCalling":onMinimized="onMinimized":onMessageSentByMe="onMessageSentByMe"/></Drag><Drag :show="showCallMini" class="callkit-drag-container-mini" domClassName="callkit-drag-container-mini"><!-- TUICallKitMini 组件:通话 UI 悬浮窗组件,提供最小化功能 --><TUICallKitMini style="position: static" /></Drag></div></template><script lang="ts">import { defineComponent, reactive, toRefs } from 'vue';import { TUIEnv } from './TUIKit/TUIPlugin';import Drag from './TUIKit/TUIComponents/components/drag';import { handleErrorPrompts } from './TUIKit/TUIComponents/container/utils';export default defineComponent({name: 'App',components: {Drag,},setup() {const data = reactive({env: TUIEnv(),currentModel: 'conversation',showCall: false,showCallMini: false,});const TUIServer = (window as any)?.TUIKitTUICore?.TUIServer;const handleCurrentConversation = (value: string) => {data.currentModel = value ? 'message' : 'conversation';};// beforeCalling:在拨打电话前与收到通话邀请前执行const beforeCalling = (type: string, error: any) => {if (error) {handleErrorPrompts(error, type);return;}data.showCall = true;};// afterCalling:结束通话后执行const afterCalling = () => {data.showCall = false;data.showCallMini = false;};// onMinimized:组件切换最小化状态时执行const onMinimized = (oldMinimizedStatus: boolean, newMinimizedStatus: boolean) => {data.showCall = !newMinimizedStatus;data.showCallMini = newMinimizedStatus;};// onMessageSentByMe:在整个通话过程内发送消息时执行const onMessageSentByMe = async (message: any) => {TUIServer?.TUIChat?.handleMessageSentByMeToView(message);return;};return {...toRefs(data),handleCurrentConversation,beforeCalling,afterCalling,onMinimized,onMessageSentByMe,};},});</script><style scoped>.home-TUIKit-main {display: flex;height: 100vh;overflow: hidden;}.search {padding: 12px;}.conversation {min-width: 285px;flex: 0 0 24%;border-right: 1px solid #f4f5f9;}.conversation-h5 {flex: 1;border-right: 1px solid #f4f5f9;}.chat {flex: 1;height: 100%;position: relative;}.callkit-drag-container {left: calc(50% - 25rem);top: calc(50% - 18rem);width: 50rem;height: 36rem;border-radius: 16px;box-shadow: rgba(0, 0, 0, 0.16) 0px 3px 6px, rgba(0, 0, 0, 0.23) 0px 3px 6px;}.callkit-drag-container-mini {width: 168px;height: 56px;right: 10px;top: 70px;}</style>
步骤6:启动项目
执行以下命令启动项目:
npm run serve
npm run dev
步骤7:发送您的第一条消息
1. 项目启动之后单击左上角发起单聊。
2. 进入发起单聊弹窗。在搜索栏输入 步骤4 中创建的 userID,选中后单击完成。
3. 在输入框中输入消息并单击发送。
Web 端 “发送您的第一条消息” 具体步骤示例:

H5 端 “发送您的第一条消息” 具体步骤示例:



步骤8:拨打您的第一通电话
自 @tencentcloud/chat-uikit-vue v1.4.0 版本起自动接入音视频通话功能,无需手动集成。
如果您是 v1.4.0 以下版本,可以通过接入 call-uikit-vue 体验通话功能。详情请参考 音视频通话 ( Web & H5 ) 。
常见问题
什么是 UserSig?
UserSig 是用户登录即时通信 IM 的密码,其本质是对 UserID 等信息加密后得到的密文。
如何生成 UserSig?
UserSig 签发方式是将 UserSig 的计算代码集成到您的服务端,并提供面向项目的接口,在需要 UserSig 时由您的项目向业务服务器发起请求获取动态 UserSig。更多详情请参见 服务端生成 UserSig。
注意
本文示例代码采用的获取 UserSig 的方案是在客户端代码中配置 SECRETKEY,该方法中 SECRETKEY 很容易被反编译逆向破解,一旦您的密钥泄露,攻击者就可以盗用您的腾讯云流量,因此该方法仅适合本地跑通功能调试。 正确的 UserSig 签发方式请参见上文。
Component name "XXXX" should always be multi-word
IM TUIKit web 所使用的 ESLint 版本为 v6.7.2 ,对于模块名的驼峰式格式并不进行严格校验。
如果您出现此问题,您可以在
.eslintrc.js
文件中进行如下配置:module.exports = {...rules: {...'vue/multi-word-component-names': 'warn',},};
ERESOLVE unable to resolve dependency tree
npm install 的时候如出现 ERESOLVE unable to resolve dependency tree ,表示依赖安装冲突,可采用以下方式进行安装:
npm install --legacy-peer-deps
如何使用 Vue2 版本接入?
即时通信 IM - 含 UI 集成方案( Web & H5 ) 目前仅支持 Vue3 版本接入,建议升级至 Vue3 版本体验最新含 UI 集成功能,或采用 无 UI 集成方案 集成 IM SDK 。