跳到正文
cccskills
免费在 GitHub 公开

vue-best-practices

Guides Vue 3 development with TypeScript, covering state, component responsibilities, and data flow. Helps organize implementation and refactoring, then review performance once the required behavior works.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

MUST be used for Vue.js tasks. Strongly recommends Composition API with `<script setup>` and TypeScript as the standard approach. Covers Vue 3, SSR, Volar, vue-tsc. Load for any Vue, .vue files, Vue Router, Pinia, or Vite with Vue work. ALWAYS use Composition API unless the project explicitly requires Options API.

查看安装方法

适用场景

  • Building Vue 3 screens with TypeScript
  • Refactoring large components
  • Clarifying state ownership and data flow
  • Reviewing performance after implementation

包含的文件(23)

  • SKILL.md10.2 KB
  • references/animation-class-based-technique.md4.9 KB
  • references/animation-state-driven-technique.md5.7 KB
  • references/component-async.md2.5 KB
  • references/component-data-flow.md10.3 KB
  • references/component-fallthrough-attrs.md4.0 KB
  • references/component-keep-alive.md3.4 KB
  • references/component-slots.md4.4 KB
  • references/component-suspense.md5.2 KB
  • references/component-teleport.md2.9 KB
  • references/component-transition-group.md2.9 KB
  • references/component-transition.md2.7 KB
  • references/composables.md8.4 KB
  • references/directives.md3.7 KB
  • references/perf-avoid-component-abstraction-in-lists.md4.6 KB
  • references/perf-v-once-v-memo-directives.md4.7 KB
  • references/perf-virtualize-large-lists.md4.9 KB
  • references/plugins.md3.8 KB
  • references/reactivity.md8.3 KB
  • references/render-functions.md3.8 KB
  • references/sfc.md6.1 KB
  • references/state-management.md3.3 KB
  • references/updated-hook-performance.md4.5 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Vue Best Practices Workflow

Use this skill as an instruction set. Follow the workflow in order unless the user explicitly asks for a different order.

Core Principles

  • Keep state predictable: one source of truth, derive everything else.
  • Make data flow explicit: Props down, Events up for most cases.
  • Decompose by responsibility: keep each implementation focused and the contracts between implementations explicit.
  • Avoid unnecessary re-renders: use computed properties and watchers wisely.
  • Readability counts: write clear, self-documenting code.

1) Confirm architecture before coding (required)

  • Default stack: Vue 3 + Composition API + <script setup lang="ts">.
  • If the project explicitly uses Options API, load vue-options-api-best-practices skill if available.
  • If the project explicitly uses JSX, load vue-jsx-best-practices skill if available.

1.1 Must-read core references (required)

  • Before implementing any Vue task, make sure to read and apply these core references:
    • references/reactivity.md
    • references/sfc.md
    • references/component-data-flow.md
    • references/composables.md
  • Keep these references in active working context for the entire task, not only when a specific issue appears.

1.2 Plan component boundaries before coding (required)

For a non-trivial feature or structural refactor, sketch responsibilities, state owners, and the contracts that cross their boundaries. For local fixes, preserve existing boundaries unless they obstruct the change.

  • Identify substantial UI responsibilities, stateful workflows, and DOM lifecycles in the affected feature. Sketch their owners, consumers, and the contracts needed for coordination.
  • Judge cohesion by behavior that changes together or maintains a shared invariant. Being on the same page, reading the same data, or having only one consumer does not by itself justify one implementation.
  • Let root/route components compose features and coordinate page behavior. Apply the same responsibility review inside feature components and composables; moving a whole feature to a child or a useFeature() function is not sufficient decomposition.
  • Follow the project's layout and scale the design to the affected behavior. A local fix does not require a project-wide component map or new architectural layers.

2) Apply essential Vue foundations (required)

These are essential, must-know foundations. Apply all of them in every Vue task using the core references already loaded in section 1.1.

Reactivity

  • Must-read reference from 1.1: reactivity
  • Keep source state minimal (ref/reactive), derive everything possible with computed.
  • Use watchers for side effects if needed.
  • Avoid recomputing expensive logic in templates.

SFC structure and template safety

  • Must-read reference from 1.1: sfc
  • Keep SFC sections in this order: <script> → <template> → <style>.
  • Keep SFC responsibilities cohesive; use the boundary criteria below when splitting.
  • Keep templates declarative; move branching/derivation to script.
  • Apply Vue template safety rules (v-html, list rendering, conditional rendering choices).

Choose useful boundaries

  • Extract substantial, separable UI responsibilities and stateful workflows when doing so reduces the code a consumer or maintainer must understand. Single-use components and composables are valid; reuse is not a prerequisite. Keep the state and event handling needed by a UI responsibility with that UI.
  • During a structural refactor, implement useful boundaries for the responsibilities identified above. Review what remains together as well as what was extracted. A small public API can hide an implementation that still needs decomposition.
  • Treat file length, UI section count, and API size as review signals, not extraction thresholds. Keep a small cohesive production feature in one SFC when extra boundaries would not hide meaningful complexity.
  • If a split adds extensive forwarding or mutual callbacks, first move local state and DOM behavior to their UI owner, then identify genuinely shared dependencies and their lifetime. Use explicit contracts or scoped context as appropriate. Merge only when the boundary has no useful responsibility to encapsulate, not merely to reduce wiring.
  • Group inputs only when they form a cohesive concept. Passing a whole controller, grouping unrelated handlers, or adding catch-all events does not reduce the dependencies consumers must understand.

Component data flow

  • Must-read reference from 1.1: component-data-flow
  • Use props down, events up as the primary model.
  • Use v-model only for true two-way component contracts.
  • Use typed, scoped provide/inject for shared descendant dependencies when intermediate components only relay them; reassess component boundaries first. See the data-flow reference for scope and ownership.
  • Keep contracts explicit and typed with defineProps, defineEmits, and InjectionKey as needed.

Composables

  • Must-read reference from 1.1: composables
  • Compose substantial stateful behavior from focused capabilities, including single-use workflows that improve code organization. Keep simple component-local logic local; use plain functions for pure calculations.
  • Distinguish implementation ownership from the public facade. A coordinator connects capabilities and implements cross-capability operations; it should not contain all their implementations or re-export all their internals.
  • Return consumer-facing state and actions. If a consumer needs unrelated groups of internals, review that consumer's responsibilities too. Encapsulate reactive bookkeeping so consumers can read current values without manually triggering invalidation.
  • Keep DOM interaction and cleanup with its owning UI or composable. Preserve the explicit coordination other features need, such as committing a pending draft before saving.

3) Consider optional features only when requirements call for them

3.1 Standard optional features

Do not add these by default. Load the matching reference only when the requirement exists.

3.2 Less-common optional features

Use these only when there is explicit product or technical need.

  • Directives: behavior is DOM-specific and not a good composable/component fit -> directives
  • Async components: heavy/rarely-used UI should be lazy loaded -> component-async
  • Render functions only when templates cannot express the requirement -> render-functions
  • Plugins when behavior must be installed app-wide -> plugins
  • State management patterns: app-wide shared state crosses feature boundaries -> state-management

4) Run performance optimization after behavior is correct

Performance work is a post-functionality pass. Do not optimize before core behavior is implemented and verified.

5) Final self-check before finishing

  • Core behavior works and matches requirements.
  • All must-read references were read and applied.
  • Reactivity model is minimal and predictable.
  • SFC structure and template rules are followed.
  • Both sides of the boundary review pass: substantial separable responsibilities are not still concentrated in one implementation, and extracted units hide useful complexity rather than merely forward it.
  • Public contracts are typed and hide internals. Trace a representative local change through the code: it should stay with its responsible UI/workflow and legitimate coordination, without unrelated forwarding edits.
  • State has explicit ownership and lifetime; shared consumers use the same intended instance, independent instances remain independent, and side effects clean up with their owner.
  • Refactors preserve existing behavior, including pending work and cross-feature operations. Use the project's applicable tests; API or file-size reductions alone are not evidence of success.
  • Optional features are used only when requirements demand them.
  • Performance changes were applied only after functionality was complete.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Create reusable Vue composables, functions that share reactive logic, accepting plain values, refs, or getters. Choose input types for reading or writing and normalize values so reactive effects track changes consistently.

中文简介正在准备中。当前显示英语简介。

  • Build reusable Vue composables
  • Update a document title when its input changes
  • Create a counter with writable input
vuejs-ai/skills31212026年10月20日 更新

Diagnose Vue 3 problems through symptom-based references covering state updates, component events, asynchronous failures, and rendering errors. Includes server-rendered pages whose HTML does not match what the browser expects when it takes over.

中文简介正在准备中。当前显示英语简介。

  • Investigating a screen that no longer updates
  • Tracking duplicate or missing component events
  • Diagnosing asynchronous loading failures
vuejs-ai/skills31212026年10月20日 更新

Write JSX, an HTML-like syntax within JavaScript, for Vue by checking how it differs from React JSX. Covers attribute conventions and JSX plugin configuration, with guidance for code migration and attribute type errors.

中文简介正在准备中。当前显示英语简介。

  • Migrating React JSX code to Vue
  • Investigating JSX attribute type errors
  • Checking class and className usage
vuejs-ai/skills31212026年10月20日 更新

Guides maintenance of Vue 3 components written with Options API. Covers TypeScript typing, access to component data through this, lifecycle methods, and accidental sharing of state between component instances.

中文简介正在准备中。当前显示英语简介。

  • Adding types to Options API components
  • Investigating this binding in methods
  • Reviewing access to data in lifecycle hooks
vuejs-ai/skills31212026年10月20日 更新

Set up Pinia stores, the shared data containers used in Vue applications, and troubleshoot state updates. Covers startup errors, destructuring that breaks screen updates, method context, and using URLs for temporary filters.

中文简介正在准备中。当前显示英语简介。

  • Investigating Pinia startup errors
  • Fixing screen updates after destructuring store values
  • Checking state returned by setup stores
vuejs-ai/skills31212026年10月20日 更新

Helps troubleshoot Vue Router 4 navigation, including checks before changing pages, URL parameter changes, and component cleanup. Use it to investigate redirect loops, stale data, and asynchronous work during navigation.

中文简介正在准备中。当前显示英语简介。

  • Investigating infinite redirect loops
  • Reviewing data updates when URL parameters change
  • Checking asynchronous API calls during navigation
vuejs-ai/skills31212026年10月20日 更新

查看 vuejs-ai 的全部技能

报告此技能的问题