Langsung ke konten
Skillpedia
Website & UI (frontend)280k Β· #257

vue-patterns

Fungsinya

Panduan ini mengajarkan praktik terbaik untuk membangun aplikasi dengan Vue.js 3, Nuxt, dan Pinia. Panduan ini membahas cara mengatur kode, membuat komponen yang bisa digunakan ulang, dan mengelola state aplikasi.

Kapan dipakai

  • βœ“Saat memulai proyek Vue.js atau Nuxt baru.
  • βœ“Saat Anda perlu merapikan kode proyek.
  • βœ“Saat membuat komponen yang bisa digunakan ulang atau mengelola data global.

Link skill

https://github.com/affaan-m/ECC/blob/main/pi/core/skills/vue-patterns/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/affaan-m/ECC/blob/main/pi/core/skills/vue-patterns/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œBagaimana sebaiknya saya mengatur file dalam proyek Vue.js?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

AI menggunakan panduan yang diberikan untuk menyarankan struktur folder, konvensi penamaan, dan urutan elemen yang tepat dalam file `.vue`.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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

…

Pertanyaan umum

Apa itu Composition API?

Composition API adalah cara yang lebih fleksibel untuk mengatur logika kode di Vue.js, menggunakan fungsi seperti `ref`, `reactive`, dan `watch`.

Apa perbedaan antara komponen Presentational dan Container?

Komponen Container mengelola data dan logika, sedangkan komponen Presentational hanya menampilkan informasi dan menerima perintah.

Kapan sebaiknya saya menggunakan Pinia alih-alih `ref` atau `reactive`?

Gunakan Pinia untuk mengelola data yang perlu dibagikan ke banyak bagian aplikasi, sedangkan `ref` dan `reactive` digunakan untuk data lokal milik sebuah komponen.

Detail

Deskripsi asli dari pembuat

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

Popularitas

Bintang GitHub
280k
Peringkat
#257
Lisensi
MIT
Diperbarui
15/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa