Design maintainable Vue 3 components: focused responsibilities, typed props and emits, v-model with defineModel, typed slots, injection keys and behaviour-focused tests.
.cursor/rules/vue-component-design.mdc. Downloaded files need to be placed in that repository path.---
description: "Design maintainable Vue 3 components: focused responsibilities, typed props and emits, v-model with defineModel, typed slots, injection keys and behaviour-focused tests."
globs: "**/*"
alwaysApply: false
---
Apply these rules when designing Vue 3 components.
## Responsibilities
- Give each component one job. Split presentational components (props in, events out) from components that load data or talk to stores.
- Use multi-word component names (`UserCard`, not `Card`) to avoid clashes with HTML elements.
## Props
- Declare props with types (`defineProps<{ ... }>()`), mark optional props with `?` and give defaults. Never mutate a prop; emit an event or use `v-model` instead.
- Prefer a few meaningful props over many Boolean flags; use a union prop (`variant: 'primary' | 'ghost'`) when flags are mutually exclusive.
## Events and v-model
- Declare emits with `defineEmits<{ select: [id: string] }>()` (named tuple syntax, Vue 3.3+). Name events in camelCase in script; templates can listen with kebab-case.
- For two-way bindings use `defineModel()` (Vue 3.4+) instead of a manual `modelValue` prop plus `update:modelValue` emit.
## Slots
- Use slots for content the parent controls (default slot for body, named slots for header/actions) and scoped slots to pass item data back. Type them with `defineSlots<{ item(props: { item: Item }): any }>()`.
## provide / inject
- Use provide/inject for compound components (Tabs → Tab, Form → Field) and app-wide services, not as a replacement for props between parent and child. Type it with an `InjectionKey<T>` symbol and give `inject` a default or throw a clear error when missing.
```ts
import type { InjectionKey, Ref } from 'vue';
export interface TabsContext {
active: Ref<string>;
select: (id: string) => void;
}
export const TabsKey: InjectionKey<TabsContext> = Symbol('Tabs');
```
## Documentation
- Add JSDoc comments to props and emits; Vue language tools show them in editor hovers. Document slots and their props.
## Testing
- Test through the public interface: mount with props, interact, assert rendered output and emitted events (Vue Test Utils or Testing Library for Vue). Do not assert on internal refs.
Cursor rules for Next.js 14+ App Router projects updated for Next.js 16 with async params, validated Route Handlers, generateMetadata and proxy.ts in place of middleware.
Cursor rules for strict TypeScript: compiler checks beyond strict, interfaces vs type aliases, real type guards, discriminated unions, utility types and branded IDs.
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.
Cursor
frontend
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A Tabs component passes the active tab down three levels with props, child Tab components mutate a prop to change selection, and v-model is implemented by hand.
Using the Vue Component Design rule, redesign src/components/Tabs.vue and Tab.vue (Vue 3.5, TypeScript).
Tabs uses defineModel for the active id and provides a typed TabsKey context; Tab injects it (throwing a clear error if used outside Tabs) and calls select(); no prop is mutated; slots are typed with defineSlots; tests mount Tabs with two Tab children, click the second, and assert the emitted update:modelValue and visible panel.
Cursor applies project rules stored as .mdc files in .cursor/rules. Each rule's frontmatter (description, globs, alwaysApply) decides whether it is always included, attached to matching files, chosen by the agent from its description, or only used when you @-mention it. Cursor also reads AGENTS.md in the project root and subdirectories for plain-Markdown instructions.
.cursor/rules/vue-component-design.mdcStarting point, not a tested configuration for your repository. Attached when files matching the globs are in context (alwaysApply: false with globs). Review the instructions, adapt the file paths and run your project's existing checks.
---
description: "Vue Component Design project conventions"
globs: "**/*"
alwaysApply: false
---
Apply these rules when designing Vue 3 components.
## Responsibilities
- Give each component one job. Split presentational components (props in, events out) from components that load data or talk to stores.
- Use multi-word component names (`UserCard`, not `Card`) to avoid clashes with HTML elements.
## Props
- Declare props with types (`defineProps<{ ... }>()`), mark optional props with `?` and give defaults. Never mutate a prop; emit an event or use `v-model` instead.
- Prefer a few meaningful props over many Boolean flags; use a union prop (`variant: 'primary' | 'ghost'`) when flags are mutually exclusive.
## Events and v-model
- Declare emits with `defineEmits<{ select: [id: string] }>()` (named tuple syntax, Vue 3.3+). Name events in camelCase in script; templates can listen with kebab-case.
- For two-way bindings use `defineModel()` (Vue 3.4+) instead of a manual `modelValue` prop plus `update:modelValue` emit.
## Slots
- Use slots for content the parent controls (default slot for body, named slots for header/actions) and scoped slots to pass item data back. Type them with `defineSlots<{ item(props: { item: Item }): any }>()`.
## provide / inject
- Use provide/inject for compound components (Tabs → Tab, Form → Field) and app-wide services, not as a replacement for props between parent and child. Type it with an `InjectionKey<T>` symbol and give `inject` a default or throw a clear error when missing.
```ts
import type { InjectionKey, Ref } from 'vue';
export interface TabsContext {
active: Ref<string>;
select: (id: string) => void;
}
export const TabsKey: InjectionKey<TabsContext> = Symbol('Tabs');
```
## Documentation
- Add JSDoc comments to props and emits; Vue language tools show them in editor hovers. Document slots and their props.
## Testing
- Test through the public interface: mount with props, interact, assert rendered output and emitted events (Vue Test Utils or Testing Library for Vue). Do not assert on internal refs.
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
Cursor's docs recommend keeping individual rules under 500 lines and splitting large rules into composable ones. Cursor's documentation states that it supports AGENTS.md in the project root and in subdirectories. Use AGENTS.md for plain-Markdown instructions you also want other tools to read, and .mdc rules when you need Cursor's scoping options (globs, description-based selection, always-apply).
Documentation checked 2026-11-05: Cursor docs: Rules
Cursor rules for Next.js 14+ App Router projects updated for Next.js 16 with async params, validated Route Handlers, generateMetadata and proxy.ts in place of middleware.
Cursor rules for strict TypeScript: compiler checks beyond strict, interfaces vs type aliases, real type guards, discriminated unions, utility types and branded IDs.
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.