🎓 A1Learner
🔍
0 of 50 lessons completed

Mounting a Vue Component

Mounting is the step that shows a Vue component on the page. The main file mounts the App component.

The main file

This file mounts the App component.

import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')

The App component

This line shows the title value.

<h1>{{ title }}</h1>

Example

<script setup>
const title = 'My Vue App'
</script>
<template>
  <div>
    <h1>{{ title }}</h1>
    <p>Vue is running.</p>
  </div>
</template>

Key points

  • Mounting is the step that shows a Vue component on the page.
  • createApp is a Vue tool that builds an app from a component.
  • The main file is named main.js and it calls createApp.
  • The app attaches to the element with the id app.

In this example, the script block holds a plain const. The const is named title. Its value is My Vue App. The markup shows that value in a heading. A short line follows the heading. The main file mounts this component with createApp(App).mount('#app').

Note

The page shows nothing until the main file mounts the app.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

Which line mounts the App component?