Getting Started with the Vue Chat UI Component in Vue 2
22 Jul 20266 minutes to read
This article provides a step-by-step guide for setting up a Vue 2 project using Vue-CLI and integrating the Syncfusion® Vue Chat UI component.
Prerequisites
| Requirement | Version |
|---|---|
| Vue | 2.6 or higher |
| Node.js | 16.0.0 or above |
Vue supported versions
| Vue version | Minimum Syncfusion Vue Chat UI version |
|---|---|
| Vue v2.7 | 20.3.47 and above |
| Vue v3.0 | 19.2.44 and above |
Browser support
| Browser | Supported versions |
|---|---|
| Chrome | Latest |
| Firefox | Latest |
| Opera | Latest |
| Edge | 13+ |
| Internet Explorer (IE) | 11+ |
| Safari | 9+ |
| iOS Safari | 9+ |
| Android Browser / Chrome for Android | 4.4+ |
| Windows Mobile | IE 11+ |
Setup the Vue 2 project
Easily set up a Vue 2 application using Vue CLI, which provides a reliable development environment, a streamlined project structure, and optimized builds compared to older setup tools. For detailed steps, refer to the Vue CLI installation instructions.
To create a new Vue 2 application, run the following commands based on your preferred package manager:
npm install -g @vue/cli
vue create quickstartor
yarn global add @vue/cli
vue create quickstartDuring the setup process, the CLI will prompt you for a few configuration options. Select the following:
- Which linter to use? → Default ([Vue 2] babel, eslint)
- Install with npm and start now? → Yes
Selecting Yes automatically installs the project dependencies and starts the development server.
After verifying that the application starts successfully, terminate the development server in the terminal and proceed to the next step.
Navigate to the project directory:
cd quickstartAdding Vue Chat UI packages
To install the Chat UI package, use the following command:
npm install @syncfusion/ej2-vue-interactive-chat --saveor
yarn add @syncfusion/ej2-vue-interactive-chatAdding CSS reference
Themes for Syncfusion® Vue components can be applied using CSS files provided through npm theme packages. For available themes, refer to the Themes documentation.
Install the Material 3 theme package using the following command:
npm install @syncfusion/ej2-material3-theme --saveThen add the following CSS reference to the src/App.vue file:
<style>
@import "../node_modules/@syncfusion/ej2-material3-theme/styles/chat-ui/index.css";
</style>Adding Chat UI component
The Chat UI code should be added in the src/App.vue file.
The user property assigns an identity to the current user, which is essential for distinguishing the user’s messages from those of other participants.
<template>
<div id='container' style="height: 380px; width: 450px; margin: 0 auto;">
<ejs-chatui :user="currentUser">
<e-messages>
<e-message :author="currentUser" text="Hi Michale, are we on track for the deadline?"></e-message>
<e-message :author="michaleUser" text="Yes, the design phase is complete."></e-message>
<e-message :author="currentUser" text="I’ll review it and send feedback by today."></e-message>
</e-messages>
</ejs-chatui>
</div>
</template>
<script>
import { ChatUIComponent, MessagesDirective, MessageDirective } from "@syncfusion/ej2-vue-interactive-chat";
export default {
components: {
'ejs-chatui': ChatUIComponent,
'e-messages': MessagesDirective,
'e-message': MessageDirective
},
data() {
return {
currentUser: {
id: "user1",
user: "Albert",
},
michaleUser: {
id: "user2",
user: "Michale Suyama",
}
};
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-interactive-chat/styles/tailwind3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/tailwind3.css";
</style>Run the application
npm run serveor
yarn run serveRegistering your Syncfusion license
Generate a license key from the Syncfusion License Dashboard and register it before rendering your Vue 2 application:
```javascript
import { registerLicense } from '@syncfusion/ej2-base';
registerLicense('YOUR_LICENSE_KEY');
```Note: A valid Syncfusion license is required for production use. Without a valid license, a trial license warning message will be displayed.
Troubleshooting
-
Chat UI not rendering styles: Ensure the theme CSS is imported in
src/App.vueand that any default Vue CLI starter styles are not overriding the Chat UI styles. -
Trial license warning banner: Register a license key via
registerLicense()from@syncfusion/ej2-base.