Vue component patterns

From Esposter/Esposter · View interactive version

Vue component patterns is an AI agent skill from the GitHub repository Esposter/Esposter. Apply when writing, typing, naming, or refactoring an individual Vue component. Esposter's Vue 3 component authoring — how one component is written, typed and named.

How to use this skill

Skill file

Vue Component Patterns (Esposter)

How an individual component is written, typed and named. Assembling a page or list _from_ components — decomposition, v-for items, action items, singleton dialogs — is the vue-page-composition skill's.

Deep dives

Shared Shell / Design-System Primitives — `references/shared-shell.md`

Cross-product chrome is a small set of shared components in apps/web/app/components/Ui/ (the UI library) and apps/web/app/components/App/ (app-chrome) — reuse them, never re-roll a bare toolbar per editor. Their design and rationale live in openspec/specs/resource/shell-cohesion/design.md.

The resource layout's page header, UiEmptyState, UiSkeleton and AppBreadcrumbs are the set; what each is for, and what a new product or editor wires up (its page's header, a launcher entry), is that page. A search of its own is a scope of the one command palette (the ui-library skill, references/keys-and-commands.md).

Same Level of Abstraction

Every statement in <script setup> sits at one conceptual level — a lower-level block moves to the store or composable that owns its concept (references/abstraction-levels.md).

Selection State: Read the Store, Don't Thread Props

A child reads the selection from the store rather than a threaded prop; local state initialised from a prop resets through :key, which names the thing rendered and is never a counter (references/selection-and-keys.md).

Async Data: Wrapper + Pure Child Pattern

Data that may arrive after mount splits into an Index.vue wrapper owning the lookup and v-if, and a pure child taking it as a required prop (references/wrapper-and-child.md).

A Registry of Heavy Components Loads on Demand — `references/async-components.md`

A map dispatching a component by type puts every entry in its importer's chunk, so a registry whose entries carry heavy vendors holds defineAsyncComponent(() => import(...)) loaders, and every render site of it puts the <component :is> inside a <Suspense> whose fallback is a UiSkeleton sized to the region. A registry of small components stays static, and a component that awaits in setup behind a v-if owes the same boundary.

Boolean Props — `is` Prefix + Default-Aware Literal Typing

A Prop, Slot Or Emit Earns Its Place By A Caller

A prop, slot or emit no call site passes or listens to is deleted with the test that pinned it, the day it is found unused: a flag added "so a future caller can opt out" is a switch nothing needs, and a spec that asks for one waits until a caller does (the over-engineering skill's catalogue row on flags, file-organization references/extraction-and-duplication.md). Before adding one, name the call site that passes it; before keeping one in review, grep its callers.

Emits — Present-Tense Event Names

Emit names are present-tense verbs: delete, update, create, save, submit — never past tense (deleted, updated, copied). The event names the action the parent should handle, not a completed fact; past-tense names also drift from Vue/DOM convention (click, submit, change).

For state-sync emits, use the update:x form where x is the state name ("update:copied": [boolean]) — the verb stays present tense; the state name may be any shape.

Template Handlers Stay Inline

A multi-statement handler is written inline in the template binding (@submit="async (_event, onComplete) => { … }"), and it stays there unless one of the exceptions the vue skill's inline-handler page holds applies (references/inline-handlers.md).

Component Folder Naming — `references/component-naming.md`

A component that gains a folder moves into it as Index.vue, never beside the folder; the folder path is the prefix and is never repeated in the filename, since Nuxt builds the auto-import name from both.

File Length

The line-count target and its exception are the file-organization skill's, "File Length". What a .vue over it is split into, and the shape a component in normal form has, is references/normal-form.md. How an extracted slot is named and where it lives is references/slots.md.

Containers — `references/structured-containers.md`

A component that frames other content owns its regions (header, body, footer), their scroll, padding and pinning, and a call site supplies content to the default and named slots and never writes a body wrapper, a footer in the default slot or a fixed body height.

Slots

Every component that renders a <slot> declares defineSlots — typed slot contracts, same as props (defineSlots<{ default: () => VNode }>(); ?: when the consumer may omit it). Forwarding an _optional_ slot into a library component that falls back to a prop needs #default + v-if on the same template, and extracting a non-trivial slot's content into its own component follows a naming convention — both in references/slots.md.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.