Compare how export default exports components and how new Vue() or createApp() bootstraps the app in Vue 2 and Vue 3, respectively.
Scalable, Secure, and High-Performance Solutions for Your Business.
Both Vue export default Vs new Vue() are used in Vue applications, but serve different purposes. Knowing what they do is crucial when working with Vue 2 and Vue 3 with modular setups.
In Vue, export default is used to define and export a component or a configuration object from a .vue or .js file. This allows other files to import and use it.
Example: Exporting a Component
// MyComponent.vueexport default { name: ‘MyComponent’,
props: [‘title’],
template: `<h1>{{ title }}</h1>`
}
This makes MyComponent importable in other components:
In Vue 2, new Vue() is used to create the root Vue instance and mount it to the DOM.
Example: Root Instance
new Vue({ render: h => h(App)
}).$mount(‘#app’)
This is the entry point in Vue 2 applications (main.js), where you mount the main component (App.vue) to the page.
In Vue 3, the root instance is created using createApp() instead of new Vue():
import { createApp } from ‘vue’import App from ‘./App.vue’
createApp(App).mount(‘#app’)
Here, App is exported via export default and then passed to createApp().
This table shows the functional and contextual differences between export default and new Vue() in Vue.js development.
| Feature | export default | new Vue() |
| Purpose | Export component/module | Initialize Vue root instance |
| Vue Version | Vue 2 & Vue 3 | Vue 2 only |
| Usage Context | Inside components/modules | Entry point (main.js) |
| Reusability | Reusable in multiple files | Used once to mount the app |
Also Read: The Top Websites Built with Vue JS
Use export default to define and share components. Use new Vue() (Vue 2) or createApp() (Vue 3) to bootstrap your app from the root.
eSparkBiz is rated 4.9 Stars
Real People, Real Stories
See why 300+ startups & enterprises trust eSparkBiz with their software outsourcingIn Vue 2, you need to explicitly install plugins using Vue.use() to add to Vue’s capabilities. This method installs the plugin globally so all components…
In Vue 3, the best way to define global variables is by adding them to app.config.globalProperties during app setup. This makes them accessible across the…
In Vue 3's Composition API, watching for prop changes is essential when you need to respond to updated values passed from a parent component. Unlike…
Let’s discuss how our dedicated experts can help.