Learn how to integrate EasyFindAi into your Vue application
Create a new Vue component to load the EasyFindAi chatbot script.
<!-- EasyFindAiChatbot.vue --><template><!-- This component doesn't render anything visible --></template><script>export default {name: 'EasyFindAiChatbot',props: {apiKey: {type: String,required: true,default: 'YOUR_API_KEY'}},mounted() {// Create script elementconst script = document.createElement('script');script.src = 'https://easyfindai.com/api/chatbot-embed?apiKey=YOUR_API_KEY';// Append to documentdocument.body.appendChild(script);// Store reference for cleanupthis.scriptElement = script;},beforeUnmount() {// Clean up when component is destroyedif (this.scriptElement && document.body.contains(this.scriptElement)) {document.body.removeChild(this.scriptElement);}}}</script>
If you're using Vue 3 with the Composition API, here's an alternative implementation:
<!-- EasyFindAiChatbot.vue (Composition API) --><template><!-- This component doesn't render anything visible --></template><script setup>import { onMounted, onBeforeUnmount, ref } from 'vue';const props = defineProps({apiKey: {type: String,required: true,default: 'YOUR_API_KEY'}});const scriptElement = ref(null);onMounted(() => {// Create script elementconst script = document.createElement('script');script.src = 'https://easyfindai.com/api/chatbot-embed?apiKey=YOUR_API_KEY';// Append to documentdocument.body.appendChild(script);// Store reference for cleanupscriptElement.value = script;});onBeforeUnmount(() => {// Clean up when component is destroyedif (scriptElement.value && document.body.contains(scriptElement.value)) {document.body.removeChild(scriptElement.value);}});</script>
Import and use the component in your main App component so it's available throughout your site.
<!-- App.vue --><template><div id="app"><!-- Your app content --><router-view /><!-- Add the chatbot component --><EasyFindAiChatbot :api-key="'YOUR_API_KEY'" /></div></template><script>import EasyFindAiChatbot from './components/EasyFindAiChatbot.vue';export default {name: 'App',components: {EasyFindAiChatbot}}</script>
Or with Vue 3 Composition API:
<!-- App.vue (Composition API) --><template><div id="app"><!-- Your app content --><router-view /><!-- Add the chatbot component --><EasyFindAiChatbot :api-key="'YOUR_API_KEY'" /></div></template><script setup>import EasyFindAiChatbot from './components/EasyFindAiChatbot.vue';</script>
If you're using Nuxt.js, you'll need to ensure the script only loads on the client side:
<!-- plugins/easyfindai-chatbot.client.js -->export default defineNuxtPlugin(() => {// Create script elementconst script = document.createElement('script');script.src = 'https://easyfindai.com/api/chatbot-embed?apiKey=YOUR_API_KEY';// Append to documentdocument.body.appendChild(script);});
The .client
suffix in the filename ensures this plugin only runs in the browser, not during server-side rendering.
Note: For Nuxt 3, make sure to place this file in the plugins
directory. For Nuxt 2, you'll need to register it in your nuxt.config.js
file.
That's it!
The chatbot will now be available on all pages of your Vue application. No additional configuration is needed!