본문으로 건너뛰기
Skillpedia
웹사이트 및 UI (프런트엔드)280k · #257

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가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/affaan-m/ECC/blob/main/pi/core/skills/vue-patterns/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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 (.vue files).
  • 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, and required/default where appropriate.
  • Boolean props: isXxx, hasXxx, canXxx.
  • Never mutate props — emit events instead.
  • For v-model binding, use defineModel() (Vue 3.4+) or modelValue + 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 use prefix.
  • Return reactive values (ref, computed, reactive), never plain primitives.
  • Accept reactive inputs via MaybeRef / toRef() / toValue().
  • Clean up side effects in onUnmounted or watcher onCleanup.
  • 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` 같은 함수를 사용합니다.

Presentational 컴포넌트와 Container 컴포넌트의 차이는 무엇인가요?

Container 컴포넌트는 데이터와 로직을 관리하고, Presentational 컴포넌트는 정보를 보여 주고 명령을 받기만 합니다.

`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.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬