بنقرة واحدة
create-component
指导在前端项目中按团队规范创建和拆分 Vue3 组件,包括目录结构、文件命名、样式与主题变量使用。当前端需要新增或重构组件时使用本技能。
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
指导在前端项目中按团队规范创建和拆分 Vue3 组件,包括目录结构、文件命名、样式与主题变量使用。当前端需要新增或重构组件时使用本技能。
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
提供 Vue 项目中页面 CSS 的命名规范。在编写页面样式或重构 CSS 时使用此技能。
提供 Vue 3 + Vite + TypeScript 项目的目录结构规范和代码组织建议。在创建新页面、组件、API 模块或重构项目结构时使用此技能。
定义 Vue 项目中 TypeScript 类型(Interface/Type)的命名规范。在定义公共类型或业务模型时调用此技能。
引导并执行 Vue 代码模块化拆分;在收到新需求或单文件代码臃肿、复用逻辑出现时调用,拆分为业务组件/公共组件、TypeScript 类型文件、hooks。
规范并校验 Vue 项目目录结构;在创建/移动/重命名文件夹或文件、生成脚手架、新增组件/页面时调用。
指导创建符合规范的API接口,包括TypeScript类型定义、接口文件组织、请求响应拦截处理。当需要创建新的API接口时使用本技能。
| name | create-component |
| description | 指导在前端项目中按团队规范创建和拆分 Vue3 组件,包括目录结构、文件命名、样式与主题变量使用。当前端需要新增或重构组件时使用本技能。 |
当你需要:
请使用本技能,并同时遵守 .agents/rules/03-项目结构.md 与 .agents/rules/04-组件规范.md。
详见 .agents/rules/04-组件规范.md 中的"组件放置决策树"。
src/components/<component-name>/src/views/<page>/components/命名约定:
kebab-case,例如 error-boundarycamelCase,例如 errorBoundary通用组件示例:
src/components/userButton/
├─ index.vue
└─ style.scss
页面级组件示例:
src/views/home/components/header/
├─ index.vue
└─ style.scss
<!-- src/components/userButton/index.vue -->
<template>
<te-button :type="type" :size="size" :class="buttonClass" @click="onClick">
<slot />
</te-button>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import type { ButtonProps } from '@tiansu/element-plus'
interface UserButtonProps {
type?: ButtonProps['type']
size?: ButtonProps['size']
className?: string
}
interface UserButtonEmits {
click: [event: Event]
}
const props = withDefaults(defineProps<UserButtonProps>(), {
type: 'primary',
size: 'medium'
})
const emit = defineEmits<UserButtonEmits>()
const buttonClass = computed(() => {
return ['user-button', props.className].filter(Boolean).join(' ')
})
const onClick = (event: Event) => {
emit('click', event)
}
</script>
<style scoped lang="scss">
.user-button {
// 样式定义
}
</style>
并在 src/components/index.ts 中集中导出:
// src/components/index.ts
export { default as UserButton } from './userButton/index.vue'
在 style.scss 中:
// src/components/userButton/style.scss
.user-button {
padding: 8px 16px;
border-radius: 4px;
border: none;
cursor: pointer;
// 使用 Element Plus 的主题变量
background-color: var(--el-color-primary);
color: var(--el-color-white);
}
原则:
.scss 文件var(--el-color-primary)、var(--el-color-text) 等var(--user-primary-color)、var(--user-border-radius) 等#1677ff。样式还原检查:涉及 UI 还原的组件样式开发,请参考对应的 UI 分析文档。
.vue 文件建议不超过 400 行,超过时优先考虑拆分为子组件。components/ 下。src/components。通用交互控件应基于 @tiansu/element-plus 进行二次封装:
<template>
<te-button :type="type" v-bind="$attrs">
<slot />
</te-button>
</template>
<script setup lang="ts">
import type { ButtonProps } from '@tiansu/element-plus'
interface Props extends ButtonProps {
// 可以扩展一些自定义属性
}
defineProps<Props>()
</script>
index.vue + style.scss 的结构?src/components/index.ts 集中导出通用组件?<script setup lang="ts"> 语法?