Vue and Nuxt
Vue 3 with Vite, or Nuxt.
Vue
Add the script tag to index.html, then call it from a component.
Ask.vue
<script setup>
import { ref } from 'vue'
const text = ref('')
const reply = ref('')
async function run() {
reply.value = (await window.charge.ai.chat(text.value)).text
}
</script>
<template>
<textarea v-model="text" />
<button @click="run">Ask</button>
<p>{{ reply }}</p>
</template> Nuxt
Load the script for every page from nuxt.config, and call it only on the client.
nuxt.config.ts
export default defineNuxtConfig({
app: {
head: {
script: [{ src: 'https://cdn.chargemy.ai/v1/charge.js', defer: true }],
},
},
}) Read next
Still stuck? Talk to us and we'll help.