vue-patterns
What it does
This guide teaches best practices for building applications with Vue.js 3, Nuxt, and Pinia. It covers how to organize your code, create reusable components, and manage your application's state.
When to use it
- βWhen starting a new Vue.js or Nuxt project.
- βWhen you need to better organize your project's code.
- βWhen creating reusable components or managing global data.
Skill link
https://github.com/affaan-m/ECC/blob/main/pi/core/skills/vue-patterns/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βHow should I organize files in a Vue.js project?β
5 new skills a week. 1 minute to read.
How it works
The AI uses the provided guidelines to suggest folder structures, naming conventions, and the correct order of elements within `.vue` files.
Technical content (original SKILL.md)
Original text by the author, straight from 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 |
β¦
FAQ
What is Composition API?
It's a more flexible way to organize your code logic in Vue.js, using functions like `ref`, `reactive`, and `watch`.
What's the difference between Presentational and Container components?
Container components manage data and logic, while Presentational components only display information and receive commands.
When should I use Pinia instead of `ref` or `reactive`?
Use Pinia to manage data that needs to be shared across many parts of your application, while `ref` and `reactive` are for a component's local data.
Details
Original description by the author
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
Popularity
- GitHub stars
- 280k
- Ranking position
- #257
- License
- MIT
- Updated
- 10/15/2026
Comments
- β¦
More skills from this repository
accessibility
280kHelps your agent create interfaces that everyone can use. Ensures websites and apps work well for people with disabilities, like those who are blind or have reduced mobility.
agent-architecture-audit
280kMakes your agent check if everything is working correctly. It finds and fixes problems in AI systems, ensuring they perform as expected.
agent-eval
280kHelps your agent compare different AI coding tools. It measures which one is faster, cheaper, and more reliable for specific tasks.
agent-harness-construction
280kMakes your agent better understand how to perform tasks. It optimizes the tools and instructions the agent uses to increase its chances of success.
Similar skills
dream-loop
260kLets your agent push a 3D scene or visual app toward high graphical quality by comparing its screenshots to concept art and iterating.
pretext
260kBuilds playful browser demos where text reflows around moving shapes, forms game levels, or breaks apart into particles.
page-agent
260kHelps your agent add a built-in AI assistant to a web app, so users can give plain-language commands that the page carries out.