🦀 ClawHub
GI Vue Component Guide
by @laimiaohua
Design and implement Vue 3 components following best practices. Use when creating Vue components, defining props/emits, or when the user asks for Vue compone...
TERMINAL
clawhub install gi-vue-component-guide📖 About This Skill
name: gi-vue-component-guide description: Design and implement Vue 3 components following best practices. Use when creating Vue components, defining props/emits, or when the user asks for Vue component structure or composition API patterns. tags: ["vue", "vue3", "component", "composition-api", "ant-design", "frontend"]
Vue 3 组件规范
按团队规范设计与实现 Vue 3 组件,适用于 Composition API + Ant Design 技术栈。
何时使用
项目结构
src/
├── components/ # 可复用组件
├── views/ # 页面级组件
├── router/
├── services/
├── stores/
├── types/
└── utils/
组件设计原则
1. 命名
UserCard.vue、DataTable.vueuserName、isLoading2. 单文件结构顺序
3. Props 定义
interface Props {
/** 用户 ID */
userId: number
/** 是否加载中 */
loading?: boolean
/** 自定义类名 */
class?: string
}const props = withDefaults(defineProps(), {
loading: false
})
?withDefaultstypes/ 导入4. Emits 定义
const emit = defineEmits<{
(e: 'update', value: string): void
(e: 'submit', payload: { id: number; name: string }): void
}>()
5. 与 Ant Design 集成
a-form + a-form-item,使用 v-model 或 v-decorator(视版本)a-table,columns 用 defineColumns 或常量a-modal,v-model:open 控制显隐a-button,type 区分 primary/default/danger6. 请求与状态
// 从 services 调用 API
import { getUserList } from '@/services/user'const loading = ref(false)
const data = ref([])
async function fetchData() {
loading.value = true
try {
data.value = await getUserList(params)
} finally {
loading.value = false
}
}
7. 类型定义
types/ 或组件同目录interface 或 type,避免 any示例模板
常见模式
header、footer)scoped,避免污染;使用 CSS 变量统一主题