[Vuejs]-Where to add code of instantiating an instance from Vue in compositional API

0👍

When creating a project with cli, an template is being initialized.
Find <div id="app> in your index.html. This is the entry point where Vue app is being mounted to. Don’t place any vue elements inside it.

Vue application created in main.ts (if you’ve chosen TypeScript):

// main.ts
import { createApp } from "vue";
import App from "./App.vue";

const app = createApp(App);

app.mount("#app");

As you see, the app uses App.vue as a root component of the application. So, you can place your logic there. Check below simple example in composition-api syntax

// App.vue
<template>
  <span>{{ message }} </span>
</template>


<script setup lang="ts">
  import { ref, onMounted } from 'vue';

  const messagge = ref('');

  onMounted(() => {
    message.value = 'Hello World';
  }
</script>

Reference

Leave a comment