vue-patterns
できること
このガイドでは、Vue.js 3、Nuxt、Piniaを使ってアプリを作るためのベストプラクティスを紹介します。コードの整理方法、再利用可能なコンポーネントの作り方、アプリの状態(ステート)の管理方法を説明します。
使う場面
- ✓Vue.jsまたはNuxtで新しいプロジェクトを始めるとき。
- ✓プロジェクトのコードをより整理したいとき。
- ✓再利用可能なコンポーネントを作ったり、グローバルなデータを管理したりするとき。
スキルのリンク
https://github.com/affaan-m/ECC/blob/main/pi/core/skills/vue-patterns/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“Vue.jsプロジェクトでは、ファイルをどのように整理すればよいですか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
AIは提供されたガイドラインをもとに、フォルダの構成、命名規則、`.vue`ファイル内の要素の正しい並び順を提案します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Vue.js Patterns and Best Practices
Comprehensive guide for Vue.js 3 development using Composition API (<script setup>), covering component design, reactivity, state management, routing, testing, and SSR patterns. Nuxt-specific guidance is included where it differs from vanilla Vue.
When to Activate
Activate this skill when:
- The project uses Vue.js (any version), Nuxt, Vite + Vue, or Pinia.
- The user asks about Vue component architecture, composables, reactivity, or state management.
- Reviewing Vue Single-File Components (
.vuefiles). - Setting up Vue Router, Pinia stores, or Vite/Vitest configuration.
- Discussing Vue-specific performance, security, or SSR patterns.
1. Project Structure
Recommended Layout (Feature-First)
src/
├── api/ # API client and endpoint definitions
├── assets/ # Static assets (images, fonts, icons)
├── components/ # Shared/reusable components
│ ├── base/ # Base UI primitives (Button, Input, Modal)
│ └── features/ # Feature-specific shared components
├── composables/ # Reusable Composition API logic
├── layouts/ # Page layouts (optional)
├── pages/ # Route-level page components
├── router/ # Vue Router configuration
├── stores/ # Pinia stores
├── types/ # TypeScript type definitions
├── utils/ # Pure utility functions
└── App.vue # Root component
File Naming
| Convention | When to Use |
|---|---|
PascalCase.vue |
All components (enforced by vue/multi-word-component-names) |
useCamelCase.ts |
Composables |
camelCase.ts |
Utilities, API clients, types |
kebab-case directories |
Route segments, feature folders |
2. Component Architecture
Single-File Component Order
<script setup lang="ts">
// 1. Imports (vue → ecosystem → absolute → relative)
// 2. Props & Emits & Slots
// 3. Composables
// 4. Local state (ref/reactive)
// 5. Computed properties
// 6. Methods
// 7. Watchers
// 8. Lifecycle hooks
</script>
<template>
<!-- Template content -->
</template>
<style scoped>
/* Scoped styles */
</style>
Presentational vs Container
- Container components: Own data fetching, state, and side effects. Render presentational components.
- Presentational components: Receive props, emit events. No API calls, no store access. Pure rendering.
Props Best Practices
// Type-based props with defaults
interface Props {
label: string;
variant?: "primary" | "secondary";
disabled?: boolean;
items: Item[];
}
const props = withDefaults(defineProps<Props>(), {
variant: "primary",
disabled: false,
});
- Always provide
type, andrequired/defaultwhere appropriate. - Boolean props:
isXxx,hasXxx,canXxx. - Never mutate props — emit events instead.
- For v-model binding, use
defineModel()(Vue 3.4+) ormodelValue+update:modelValue.
Events
const emit = defineEmits<{
submit: [];
"update:modelValue": [value: string];
select: [id: string, index: number];
}>();
- Use kebab-case in templates (
@update:model-value). - Use camelCase in script (
emit("update:modelValue", val)).
3. Composables (Reusable Logic)
Structure
// composables/useDebounce.ts
export function useDebounce<T>(value: MaybeRef<T>, delay: number): Ref<T> {
const debounced = ref(toValue(value)) as Ref<T>;
let timer: ReturnType<typeof setTimeout>;
watch(
() => toValue(value),
(newVal) => {
clearTimeout(timer);
timer = setTimeout(() => { debounced.value = newVal; }, delay);
}
);
onUnmounted(() => clearTimeout(timer));
return readonly(debounced);
}
Rules
- Must start with
useprefix. - Return reactive values (
ref,computed,reactive), never plain primitives. - Accept reactive inputs via
MaybeRef/toRef()/toValue(). - Clean up side effects in
onUnmountedor watcheronCleanup. - No module-scope side effects.
vs Mixins
Composables replace Vue 2 mixins entirely:
- Mixins: Opaque data flow, source-of-truth collisions, name conflicts.
- Composables: Explicit imports, clear return values, composable and tree-shakable.
4. State Management
When to Use What
| Pattern | Use Case |
|---|---|
ref() / reactive() |
Local component state |
| Props + Emits | Parent-child communication |
| Provide / Inject | Theme, config, plugin API |
…
よくある質問
Composition APIとは何ですか?
Vue.jsでコードのロジックを整理するためのより柔軟な方法で、`ref`、`reactive`、`watch`などの関数を使います。
プレゼンテーショナルコンポーネントとコンテナコンポーネントの違いは何ですか?
コンテナコンポーネントはデータとロジックを管理します。プレゼンテーショナルコンポーネントは情報を表示するだけで、親から受け取った指示に従います。
`ref`や`reactive`ではなくPiniaを使うべきなのはいつですか?
アプリの多くの部分で共有する必要があるデータを管理するときはPiniaを使います。`ref`や`reactive`は、コンポーネント内だけで使うローカルなデータ向けです。
詳細
作者による元の説明
Vue.js 3 Composition API patterns, component architecture, reactivity best practices, Pinia state management, Vue Router navigation, and Nuxt SSR patterns. Activates for Vue, Nuxt, Vite, or Pinia projects. Use when building or reviewing Vue 3, Nuxt, or Pinia code — Composition API, reactivity, or router navigation.
repo: affaan-m/ECC
人気
- GitHubのスター
- 280k
- ランキング
- #257
- ライセンス
- MIT
- 更新日
- 2026/10/15
コメント
- …
このリポジトリの他のスキル
accessibility
280kエージェントが誰にとっても使いやすいインターフェースを作れるように手助けします。目が見えない方や身体の動きに制限のある方など、障害のある人にとってもWebサイトやアプリが正しく動くようにします。
agent-architecture-audit
280kエージェントがすべて正しく動いているかを確認できるようにします。AIシステムの問題を見つけて修正し、期待どおりに動くようにします。
agent-eval
280kエージェントが異なるAIコーディングツールを比較できるようにします。特定のタスクにおいて、どれがより速く、安く、信頼性が高いかを測定します。
agent-harness-construction
280kエージェントがタスクの進め方をよりよく理解できるようにします。エージェントが使うツールや指示を最適化し、成功する可能性を高めます。
似ているスキル
dream-loop
260kコンセプトアートと比べながら、ライブのスクリーンショットを繰り返し確認して、3Dのシーンやビジュアルアプリを高いグラフィック品質に近づけるようエージェントを支援します。
pretext
260kテキストが動く図形の周りに回り込んだり、ゲームのレベルを形作ったり、粒子になって崩れたりする、遊び心のあるブラウザのデモを作るようエージェントを支援します。
page-agent
260kウェブアプリに組み込みのAIアシスタントを加え、利用者が平易な言葉で命令し、ページがそれを実行できるようにするのを、エージェントが支援します。