Vue¶
Scope: web apps built with Vue 3, the Composition API and Single-File Components, with Pinia for shared state and Vue Router for routing, plus Nuxt (version 4) where it changes the architecture: server rendering, data fetching and server routes. Framework-independent rules for accessibility, performance and security, such as WCAG, Core Web Vitals, sanitizing HTML before v-html and Content Security Policy, are in Web front end. Nuxt server routes are backend code, so the Node.js and Security guidelines also apply to them.
Entries are sorted by score from 1 to 10 (criteria): 9โ10 start here or strongly recommended, 6โ8 recommended, 1โ5 further reading or conditional.
Adopted references¶
- 9 Vue.js Guide: the baseline. Essentials, components, composables, the Scaling Up chapters (Single-File Components, tooling, routing, state management, testing and server-side rendering), the Best Practices chapters (production deployment, performance, accessibility and security) and TypeScript.
- 9 Vue Style Guide: the official Vue-specific coding rules in four priorities. Follow Priority A (Essential) and Priority B (Strongly Recommended); eslint-plugin-vue has a rule category for each priority.
- 9 Nuxt documentation: the baseline for Nuxt apps: rendering modes, data fetching, state management, server routes, runtime config and best practices.
- 8 Vue.js, Security: what Vue escapes for you, the remaining HTML, URL, style and JavaScript injection risks, and coordination with the backend.
- 8 Pinia: the official store library: defining stores, state, getters, actions, plugins, server-side rendering and testing.
- 8 Vue Router guide: the official router: dynamic and nested routes, navigation guards, route meta fields, lazy loading and typed routes.
- 7 Vue.js, Performance: Vue-specific page load and update optimizations, such as choosing the architecture, code splitting, props stability, list virtualization and reducing reactivity overhead.
- 7 Nuxt performance: Nuxt's built-in features for links, hybrid rendering, lazy components and lazy hydration, the core modules for images, fonts and third-party scripts, and common problems.
Key rules¶
Components and reactivity¶
- 8
VUE-1Never mutate props, including nested properties of object props: emit an event so that the parent changes its own state, or usedefineModel()for two-way binding. Props form a one-way-down binding, and mutating them lets a child change its parent's state in ways that are hard to follow. (Vue.js, One-way data flow, Component v-model) - 7
VUE-2Write application components as Single-File Components with the Composition API and<script setup>. The guide recommends this combination for full applications and the Options API for apps without build tools or with low complexity. (Vue.js, Which to choose?,<script setup>) - 7
VUE-3Derive values withcomputed, keep computed getters free of side effects, and use watchers only for side effects in reaction to state changes. A getter must not mutate other state, make requests or change the DOM, and its value is a read-only snapshot. (Vue.js, Computed properties: best practices, Watchers) - 7
VUE-4Declare props and emitted events with types, such asdefineProps<Props>(), and type-check.vuefiles in CI withvue-tsc. Vite only transpiles TypeScript and doesn't type-check it. (Vue.js, Using Vue with TypeScript, Style Guide, Use detailed prop definitions) - 6
VUE-5Extract reusable stateful logic into composables: name themuseX, accept refs or getters and read them withtoValue(), return a plain object of refs, and call them synchronously in<script setup>orsetup(). (Vue.js, Composables: conventions and best practices)
State and data fetching¶
- 9
VUE-6In server-rendered apps, never keep user or request data in module-level state: create the app, router and stores for each request, and in Nuxt keep shared state inuseStateor Pinia, not in refs exported from a module. The server reuses modules across requests, so one user's data can leak into another user's response. (Vue.js, Cross-request state pollution, Nuxt, State management: best practices, Pinia, Why should I use Pinia?) - 7
VUE-7Use Pinia for state that many components share, instead of hand-rolled globalreactive()objects. Pinia adds DevTools integration, server-side rendering support, plugins and type inference. Vuex is in maintenance mode. (Vue.js, State management: Pinia, Pinia, Introduction) - 7
VUE-8In Nuxt, load the data a page renders withuseFetchoruseAsyncData, keep$fetchfor requests that user events trigger, and usepickortransformto keep only the fields the page renders.$fetchalone in setup can fetch the data twice, on the server and again during hydration. The composables forward the server's result to the browser in the page payload. (Nuxt, The need for useFetch and useAsyncData, Minimize payload size) - 6
VUE-9Render the same output on the server and in the browser: use SSR-safe composables, keep browser-only code inonMounted()or<ClientOnly>, and don't render values that differ between the two, such as the current time. Hydration mismatches delay interactivity and can leave buttons and forms without event listeners. (Nuxt, Nuxt and hydration, Vue.js, Hydration mismatch)
Routing and rendering¶
- 7
VUE-10Use server-side rendering or static generation, for example with Nuxt, when page load performance or SEO matters, and a client-side SPA only when they don't. In Nuxt, set the rendering mode per route withrouteRules. (Vue.js, Performance: choosing the right architecture, Vue.js, Why SSR?, Nuxt, Hybrid rendering) - 7
VUE-11Lazy-load route components with dynamic imports. The Vue performance guide strongly recommends it for apps that use Vue Router: each route becomes a separate chunk that loads on the first visit. (Vue.js, Code splitting, Vue Router, Lazy loading routes) - 6
VUE-12Put an element withtabindex="-1"at the top ofApp.vue, just before a skip link to the main content, and focus it in a watcher on Vue Router's current route. Each route change then moves focus back to the start of the page. This is how Vue appliesWEB-22. (Vue.js, Accessibility: skip link)
Security¶
- 9
VUE-13Never use untrusted content as a Vue template, and never mount Vue on server-rendered HTML that contains user-provided content. Template expressions run as JavaScript, also during server-side rendering. Forv-html, follow the XSS rules in Web front end. (Vue.js, Security: Rule No.1, Potential dangers) - 9
VUE-14Give an environment variable theVITE_prefix, or put a value in Nuxt'sruntimeConfig.public, only if it may be public. Vite bundlesVITE_variables into the client code, and Nuxt adds public runtime config to every page payload. Keep secrets in privateruntimeConfigkeys, and don't render them or pass them touseState. (Vite, Env variables, Nuxt, Runtime config)
Testing¶
- 6
VUE-15Run unit and component tests with Vitest, give each component its own component test, and in those tests interact with the component as a user would instead of mocking its child components. This appliesWEB-14in Web front end. (Vue.js, Testing: component testing)
How to enforce¶
Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.
- 7 eslint-plugin-vue: the official linter for Single-File Components, with rule categories that follow the Style Guide's priorities.
vue/no-mutating-propsflags mutated props, andvue/no-side-effects-in-computed-propertiesandvue/no-async-in-computed-propertiesflag impure computed getters. Among the opt-in rules,vue/component-api-styleallows only<script setup>and the Composition API, andvue/define-props-declarationandvue/define-emits-declarationrequire type-based declarations. In Nuxt, the ESLint module generates a project-aware config that includes the plugin's recommended rules. ChecksVUE-1,VUE-2andVUE-3, and partlyVUE-4. - 7 vue-tsc: type-checks
.vuefiles from the command line. Runvue-tsc --noEmitin CI, ornuxt typecheckin a Nuxt app. Partly checksVUE-4.
Tutorials and further reading¶
- 7 Vue.js Tutorial: the official interactive tutorial, which introduces Vue's core features step by step in the browser, in either API style.
- 6 Vue Test Utils guide: the official component testing library's guide, from mounting components to testing emitted events, forms, slots, asynchronous behaviour, HTTP requests and Vue Router.
- 6 Composition API FAQ (Vue.js): why the Composition API exists, and how it compares with the Options API and React Hooks.
- 6 Vue patterns (Patterns.dev): Vue-specific patterns such as composables,
<script setup>, state management, provide/inject and dynamic components.