The main.js
file in a Vue.js project serves as the entry point for the application. It’s where the Vue instance is created, configured, and mounted to the DOM.
main.js
public/index.html
(usually #app
).main.js
, making them available across the entire app.main.js
file mounts the root component (App.vue
) to a specific HTML element (typically <div id="app"></div>
in index.html
), rendering the Vue application on the page.main.js
Here’s an example main.js
file:
// Import Vue
import { createApp } from 'vue';
// Import the root component
import App from './App.vue';
// Import global CSS (optional)
import './assets/global.css';
// Import plugins
import router from './router'; // Vue Router for navigation
import store from './store'; // Vuex store for state management
// Create the app instance
const app = createApp(App);
// Register plugins
app.use(router); // Register Vue Router
app.use(store); // Register Vuex store
// Mount the app instance to the DOM
app.mount('#app'); // Links to <div id="app"></div> in index.html