Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Vue 3 debugging reference for reactivity issues, computed errors, watcher bugs, async failures, and SSR hydration problems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
reference/mount-return-value.md
1---2title: mount() Returns Component Instance, Not App Instance3impact: MEDIUM4impactDescription: Using mount() return value for app configuration silently fails5type: capability6tags: [vue3, createApp, mount, api]7---89# mount() Returns Component Instance, Not App Instance1011**Impact: MEDIUM** - The `.mount()` method returns the root component instance, not the application instance. Attempting to chain app configuration methods after mount() will fail or produce unexpected behavior.1213This is a subtle API detail that catches developers who assume mount() returns the app for continued chaining.1415## Task Checklist1617- [ ] Never chain app configuration methods after mount()18- [ ] If you need both instances, store them separately19- [ ] Use the component instance for accessing root component state or methods20- [ ] Use the app instance for configuration, plugins, and global registration2122**Incorrect:**23```javascript24import { createApp } from 'vue'25import App from './App.vue'2627// WRONG: Assuming mount returns app instance28const app = createApp(App).mount('#app')2930// This fails! app is actually the root component instance31app.use(router) // TypeError: app.use is not a function32app.config.errorHandler = fn // app.config is undefined33```3435```javascript36// WRONG: Trying to save both in one line37const { app, component } = createApp(App).mount('#app') // Doesn't work this way38```3940**Correct:**41```javascript42import { createApp } from 'vue'43import App from './App.vue'4445// Store app instance separately46const app = createApp(App)4748// Configure the app49app.use(router)50app.config.errorHandler = (err) => console.error(err)5152// Store component instance if needed53const rootComponent = app.mount('#app')5455// Now you have access to both:56// - app: the application instance (for config, plugins)57// - rootComponent: the root component instance (for state, methods)58```5960```javascript61// If you only need the app configured and mounted (most common case):62createApp(App)63.use(router)64.use(pinia)65.mount('#app') // Return value (component instance) discarded - that's fine66```6768## When You Need the Root Component Instance6970```javascript71const app = createApp(App)72const vm = app.mount('#app')7374// Access root component's exposed state/methods75console.log(vm.someExposedProperty)76vm.someExposedMethod()7778// In Vue 3 with <script setup>, use defineExpose to expose:79// <script setup>80// import { ref } from 'vue'81// const count = ref(0)82// defineExpose({ count })83// </script>84```8586## Reference87- [Vue.js - Mounting the App](https://vuejs.org/guide/essentials/application.html#mounting-the-app)88- [Vue.js Application API - mount()](https://vuejs.org/api/application.html#app-mount)89