Vue Chat - Popup Integration
A common way to add a chat assistant to your website is by embedding it in a modal at the bottom right corner. Follow these steps:
- Place DevExtreme Floating Action Button at the bottom right of the window. Users can click it to open the popup.
- Position our Popup at the bottom right (or another preferred location).
- Add the Chat component for the virtual assistant.
The following code snippet demonstrates this scenario. Check the CSS tab for instructions on how to integrate Popup and Chat.
Code
- <!-- App.vue -->
- <template>
- <DxSpeedDialAction
- label="Chat"
- icon="send"
- @click="showPopup"
- />
- <DxPopup
- v-model:visible="popupVisible"
- :width="400"
- :height="650"
- :shading="false"
- :drag-enabled="false"
- position="right bottom"
- >
- <DxChat #chat
- :width="400"
- :height="600"
- :items="messages"
- @message-entered="onMessageEntered"
- >
- </DxChat>
- </DxPopup>
- </template>
- <script setup lang="ts">
- import { DxChat, DxSpeedDialAction, DxPopup } from 'devextreme-vue';
- import type { DxChatTypes } from 'devextreme-vue/chat';
- import { ref, type Ref } from 'vue';
- const assistant: DxChatTypes.User = {
- id: "02",
- name: "Assistant",
- };
- const messages: Ref<DxChatTypes.Message[]> = ref([{
- id: 1,
- timestamp: new Date(),
- author: assistant,
- text: "Hello! How can I help you?"
- }]);
- const popupVisible = ref(false);
- const onMessageEntered = (e: DxChatTypes.MessageEnteredEvent) => {
- messages.value = [...messages.value, e.message];
- }
- const showPopup = () => {
- popupVisible.value = true;
- }
- </script>
- <style>
- #chat {
- border: none;
- }
- .dx-popup-content-scrollable {
- padding: 0;
- overflow: hidden;
- }
- </style>