Having trouble getting help?
Contact Support
Contact Support
Load on-demand in Vue Chat UI component
18 Dec 20243 minutes to read
You can use the loadOnDemand property to load messages dynamically when the scroll reaches the top of the message list improving performance and reducing load times, particularly in long conversations. This ensures a smooth user experience by only fetching messages as needed rather than loading the entire conversation at once.
<template>
<div id='container' style="height: 380px; width: 450px; margin: 0 auto;">
<ejs-chatui :user="currentUser" :loadOnDemand="true" :messages="chatMessages"></ejs-chatui>
</div>
</template>
<script setup>
import { ChatUIComponent as EjsChatui } from "@syncfusion/ej2-vue-interactive-chat";
const currentUser = {
id: "user1",
user: "Albert"
};
const michaleUser = {
id: "user2",
user: "Michale Suyama"
};
let chatMessages = [];
chatMessages = Array.from({ length: 150 }, (_, i) => ({
text: i % 2 === 0
? `Message ${i + 1} from Michale`
: `Message ${i + 1} from Albert`,
author: (i % 2 === 0) ? this.michaleUser : this.currentUser
}));
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-interactive-chat/styles/material.css";
</style>
<template>
<div id='container' style="height: 380px; width: 450px; margin: 0 auto;">
<ejs-chatui :user="currentUser" :loadOnDemand="true" :messages="chatMessages" :created="created"></ejs-chatui>
</div>
</template>
<script>
import { ChatUIComponent } from "@syncfusion/ej2-vue-interactive-chat";
export default {
components: {
'ejs-chatui': ChatUIComponent
},
data() {
return {
currentUser: {
id: "user1",
user: "Albert",
},
michaleUser: {
id: "user2",
user: "Michale Suyama",
},
chatMessages: []
};
},
methods: {
created() {
this.chatMessages = Array.from({ length: 150 }, (_, i) => ({
text: i % 2 === 0
? `Message ${i + 1} from Michale`
: `Message ${i + 1} from Albert`,
author: (i % 2 === 0) ? this.michaleUser : this.currentUser
}));
}
}
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-interactive-chat/styles/material.css";
</style>