vue-best-practices
vuejs-ai/skills · Agent Skill
Vue的主要開發指南,涵蓋元件架構、反應性和可維護的程式碼。
前往安裝 ↓總覽
| 發布者 | |
|---|---|
| 儲存庫 | vuejs-ai/skills ↗ |
| 技能資料夾 | vue-best-practices |
| 星 | 3,151 |
| 分支 | 184 |
| 附帶檔案 | 23 |
| 授權 | MIT |
| 最近更新 | 2026年10月23日 |
| 連結 | 技能原始碼 ↗ · 儲存庫 ↗ |
Mozgi 檢查
我們在技能檔案中發現的內容。詳細資訊需訂閱。
安裝
技能就是一個含 SKILL.md 的資料夾。選擇你的代理,在專案根目錄的終端機(macOS、Linux 或 Windows 的 Git Bash)執行指令。
把提示貼到 Claude、Codex 或其他助理:它會自行檢查並安裝技能。
Install the “vue-best-practices” skill from mozgi.io (https://mozgi.io/skills/vuejs-ai-vue-best-practices/) for me. 1. Download the archive: https://mozgi.io/skills/vuejs-ai-vue-best-practices/download If it fails, take the skill folder from the source: https://github.com/vuejs-ai/skills/tree/main/skills/vue-best-practices 2. Read SKILL.md and the other files. Check the skill is safe: no hidden commands, no sending data elsewhere, no scripts doing something other than described. If anything looks suspicious, stop and tell me. 3. Put the “vue-best-practices” folder into your agent's skills folder: .claude/skills/ for Claude Code, .agents/skills/ for Codex, .cursor/skills/ for Cursor, .gemini/skills/ for Gemini CLI. Inside the project if we are in one, otherwise in the home folder (~/.claude/skills/ etc.). 4. Make sure <skills folder>/vue-best-practices/SKILL.md exists. 5. Briefly tell me what this skill does and offer to try it on my task. If you cannot do a step yourself, tell me what to click or type.
git clone --depth 1 --branch main https://github.com/vuejs-ai/skills.git /tmp/skills mkdir -p .claude/skills cp -r /tmp/skills/skills/vue-best-practices .claude/skills/vue-best-practices
重新啟動 Claude Code — 技能就會出現在清單中,手動呼叫:/vue-best-practices。要套用到所有專案,請放在 ~/.claude/skills。
git clone --depth 1 --branch main https://github.com/vuejs-ai/skills.git /tmp/skills mkdir -p .agents/skills cp -r /tmp/skills/skills/vue-best-practices .agents/skills/vue-best-practices
Codex 會從目前資料夾往上到儲存庫根目錄,在 .agents/skills 中尋找技能;用 /skills 或 $vue-best-practices 呼叫。所有專案:~/.agents/skills。
git clone --depth 1 --branch main https://github.com/vuejs-ai/skills.git /tmp/skills mkdir -p .cursor/skills cp -r /tmp/skills/skills/vue-best-practices .cursor/skills/vue-best-practices
Cursor 啟動時會載入技能;在 Agent 聊天輸入「/」呼叫。Cursor 也會讀取 .claude/skills 與 .agents/skills。所有專案:~/.cursor/skills。
git clone --depth 1 --branch main https://github.com/vuejs-ai/skills.git /tmp/skills mkdir -p .gemini/skills cp -r /tmp/skills/skills/vue-best-practices .gemini/skills/vue-best-practices
任務符合時,Gemini CLI 會提議啟用技能,由你確認。所有專案:~/.gemini/skills。
安裝前請先檢視 SKILL.md 與相關檔案。點擊檔案即可預覽。
SKILL.md 內容
作者原文 · 唯讀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-practicesskill if available. - If the project explicitly uses JSX, load
vue-jsx-best-practicesskill 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.mdreferences/sfc.mdreferences/component-data-flow.mdreferences/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 withcomputed. - 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-modelonly 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, andInjectionKeyas 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.
- Slots: parent needs to control child content/layout -> component-slots ↗
- Fallthrough attributes: wrapper/base components must forward attrs/events safely -> component-fallthrough-attrs ↗
- Built-in component
<KeepAlive>for stateful view caching -> component-keep-alive ↗ - Built-in component
<Teleport>for overlays/portals -> component-teleport ↗ - Built-in component
<Suspense>for async subtree fallback boundaries -> component-suspense ↗ - Animation-related features: pick the simplest approach that matches the required motion behavior.
- Built-in component
<Transition>for enter/leave effects -> transition ↗ - Built-in component
<TransitionGroup>for animated list mutations -> transition-group ↗ - Class-based animation for non-enter/leave effects -> animation-class-based-technique ↗
- State-driven animation for user-input-driven animation -> animation-state-driven-technique ↗
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.
- Large list rendering bottlenecks -> perf-virtualize-large-lists ↗
- Static subtrees re-rendering unnecessarily -> perf-v-once-v-memo-directives ↗
- Over-abstraction in hot list paths -> perf-avoid-component-abstraction-in-lists ↗
- Expensive updates triggered too often -> updated-hook-performance ↗
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.
常見問題
vue-best-practices 技能有什麼用途?
Vue的主要開發指南,涵蓋元件架構、反應性和可維護的程式碼。
如何安裝 vue-best-practices?
打開本頁的「安裝」區塊並選擇你的代理 — Claude Code、Codex、Cursor 或 Gemini CLI:那裡有把技能資料夾複製到正確位置的現成指令。也可以複製「透過助理」分頁中的提示,讓助理自行檢查並安裝技能。
vue-best-practices 適用哪些 AI 模型?
技能是純 Markdown 指示(Agent Skills 格式),因此 vue-best-practices 適用任何讀取 SKILL.md 的代理:Claude Code、Codex、Cursor、Gemini CLI、GitHub Copilot、OpenCode 等。只有在任務符合技能描述時,模型才會載入指示。
vue-best-practices 是免費的嗎?
此技能由 vuejs-ai 公開發布,採用 MIT 授權。技能本身免費 — 你只需向 AI 供應商支付實際使用的 token 費用。
安裝技能安全嗎?
技能是代理會遵循的指示,安裝前請閱讀 SKILL.md 及相關檔案。技能資料夾中的腳本只有在代理執行時才會運行 — 留意它的動作,不要授予多餘權限。
技能和 MCP 伺服器或外掛有何不同?
MCP 伺服器或外掛為模型提供新工具 — 會執行並回傳結果的程式碼。技能提供的是知識與流程:如何處理任務、要遵循哪些步驟、好的成果長什麼樣子。它不需要伺服器或 API 金鑰。