create-vue-component
星标4
分支0
更新时间2025年12月28日 07:09
Nuxt 4プロジェクトで新しいVue 3コンポーネントを作成する際のテンプレートとガイドライン
安装
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
SKILL.md
readonly菜单
Nuxt 4プロジェクトで新しいVue 3コンポーネントを作成する際のテンプレートとガイドライン
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | create-vue-component |
| description | Nuxt 4プロジェクトで新しいVue 3コンポーネントを作成する際のテンプレートとガイドライン |
このスキルは、「いぬいのうた」プロジェクトでVue 3コンポーネントを作成する際の標準テンプレートと手順を提供します。
<script setup lang="ts">
interface Props {
title: string;
count: number;
}
interface Emits {
(e: 'update', value: number): void;
}
const props = defineProps<Props>();
const emit = defineEmits<Emits>();
const handleClick = () => {
emit('update', props.count + 1);
};
</script>
<template>
<div>
<h2>{{ title }}</h2>
<button @click="handleClick">Count: {{ count }}</button>
</div>
</template>
app/components/app/components/layout/ (自動的にグローバル登録される)app/components/[feature]/ (例: app/components/player/)SongRow.vue, VideoPlayer.vue, PlaylistItem.vue<script setup lang="ts">
// 1. Props定義(必須の場合)
interface Props {
// Props型定義
}
// 2. Emits定義(イベント送信する場合)
interface Emits {
(e: 'eventName', payload: PayloadType): void;
}
// 3. Props/Emitsの登録
const props = defineProps<Props>();
const emit = defineEmits<Emits>();
// 4. リアクティブな状態
const localState = ref<Type>(initialValue);
const computed = computed(() => {
// 算出プロパティ
});
// 5. メソッド定義
const handleAction = () => {
// ロジック
emit('eventName', payload);
};
// 6. ライフサイクル(必要な場合)
onMounted(() => {
// マウント時の処理
});
</script>
<template>
<div class="container">
<!-- UI実装 -->
</div>
</template>
✅ TypeScript strict モード準拠
any 型の使用禁止✅ Composition API
<script setup> を必ず使用✅ 単一責任の原則
✅ Props/Emitsの明示
❌ Options API (data(), methods, computed)
❌ Props の直接変更
❌ 直接的な DOM 操作
❌ グローバル状態への直接アクセス
app/components/layout/ 内のコンポーネントは自動的にグローバル登録されます:
app/components/layout/Header.vue → <LayoutHeader />
app/components/layout/Footer.vue → <LayoutFooter />
app/components/layout/Sidebar.vue → <LayoutSidebar />
複雑なロジックは Composables に抽出:
// composables/useSomething.ts
export const useSomething = () => {
const state = ref(initialValue);
const action = () => {
// ロジック
};
return { state, action };
};
コンポーネント内で使用:
<script setup lang="ts">
const { state, action } = useSomething();
</script>
Tailwind CSS のユーティリティクラスを使用:
<template>
<div class="flex items-center gap-4 p-4 bg-gray-100 rounded-lg">
<h2 class="text-xl font-bold">{{ title }}</h2>
<button class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
ボタン
</button>
</div>
</template>
レスポンシブデザイン:
<template>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<!-- モバイル: 1列、タブレット: 2列、デスクトップ: 3列 -->
</div>
</template>
コンポーネント作成完了時に確認:
<script setup lang="ts"> を使用