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/configure-app-before-mount.md
1---2title: Configure Vue App Before Calling mount()3impact: HIGH4impactDescription: App configurations after mount() are silently ignored, causing missing plugins and handlers5type: capability6tags: [vue3, createApp, mount, configuration, setup]7---89# Configure Vue App Before Calling mount()1011**Impact: HIGH** - Any app configurations applied after `.mount()` is called are silently ignored. This includes error handlers, global components, directives, and plugins, leading to mysterious missing functionality.1213The `.mount()` method should always be called after all app configurations and asset registrations are done. This is a critical ordering requirement that, when violated, produces no errors but causes features to silently fail.1415## Task Checklist1617- [ ] Register all plugins (router, store, etc.) before mount()18- [ ] Configure error handlers before mount()19- [ ] Register global components and directives before mount()20- [ ] Set all `app.config` properties before mount()21- [ ] Call `.mount()` as the final step in app initialization2223**Incorrect:**24```javascript25import { createApp } from 'vue'26import App from './App.vue'27import router from './router'2829const app = createApp(App)3031// WRONG: Mounting first, then configuring32app.mount('#app')3334// These are silently IGNORED - app is already mounted!35app.use(router)36app.config.errorHandler = (err) => {37console.error('Global error:', err)38}39app.component('GlobalButton', GlobalButton)40```4142**Correct:**43```javascript44import { createApp } from 'vue'45import App from './App.vue'46import router from './router'47import { createPinia } from 'pinia'48import GlobalButton from './components/GlobalButton.vue'4950const app = createApp(App)5152// Configure everything FIRST53app.use(router)54app.use(createPinia())5556// Set up error handling57app.config.errorHandler = (err, instance, info) => {58console.error('Global error:', err)59console.log('Component:', instance)60console.log('Error info:', info)61}6263// Register global components64app.component('GlobalButton', GlobalButton)6566// Mount LAST - after all configuration is complete67app.mount('#app')68```6970## Common Mistake: Chaining with Mount7172```javascript73// WRONG: Chaining mount in the middle of configuration74createApp(App)75.use(router)76.mount('#app') // Everything after this line is a problem77.use(pinia) // This doesn't even work - mount returns component instance!7879// CORRECT: Either complete chain before mount, or use intermediate variable80createApp(App)81.use(router)82.use(pinia)83.component('GlobalButton', GlobalButton)84.mount('#app') // Mount at the very end85```8687## Reference88- [Vue.js - Creating a Vue Application](https://vuejs.org/guide/essentials/application.html)89- [Vue.js Application API](https://vuejs.org/api/application.html)90