kwc-vue-development
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseKWC Vue 开发专家
KWC Vue Development Expert
本 Skill 是 KWC Vue 项目开发的入口与总指挥。基于 Vue 3 (Composition API + ) 进行开发。
<script setup>This Skill is the entry point and commander-in-chief for KWC Vue project development. Development is based on Vue 3 (Composition API + ).
<script setup>核心职责
Core Responsibilities
你负责指导用户进行 KWC Vue 组件的开发、修改和维护。
重要:你必须严格遵守本 Skill 目录下的 文件中定义的硬性约束。在开始任何代码编写前,请务必阅读并理解这些规则。
rule.mdYou are responsible for guiding users in the development, modification and maintenance of KWC Vue components.
Important: You must strictly follow the hard constraints defined in the file in this Skill directory. Be sure to read and understand these rules before starting any code writing.
rule.md1. 环境上下文确认
1. Environment Context Confirmation
- 项目根目录:包含 文件夹和
.kd目录。app/kwc - 配置环境:中
.kd/config.json为framework。vue - 重要:若当前环境不满足上述条件,必须立即停止使用本 Skill 的所有约束,转而按通用 Vue Web 项目标准协助用户。
- Project Root Directory: Contains folder and
.kddirectory.app/kwc - Configuration Environment: in
frameworkis set to.kd/config.json.vue - Important: If the current environment does not meet the above conditions, you must immediately stop using all constraints of this Skill, and instead assist users according to general Vue Web project standards.
2. Vue 3 开发基础
2. Vue 3 Development Basics
本项目基于 Vue 3,必须遵循以下基本原则:
- Composition API:统一使用 语法,禁止使用 Options API(
<script setup>)export default { data(), methods, computed, watch } - 响应式:使用 /
ref()声明响应式状态,禁止使用reactive()。向 Web Components 传递复杂数据(对象/数组)时,由于底层需检测引用变化,绝对禁止this或push原地修改,必须通过重新赋值(如splice)产生新引用来触发渲染。data.value = [...data.value, new] - 生命周期:使用 /
onMounted()等 Composition API 钩子onUnmounted() - 模板语法:
- 属性绑定:
:prop="value" - 事件绑定:(Shoelace 组件使用
@sl-change="handler"前缀)@sl-* - 向 Web Component 传递对象/数组属性:必须用 camelCase + 修饰符:
.prophtml【✅ 正确】 <sl-table :dataSource.prop="rows" :columns.prop="cols" :rowSelection.prop="sel"></sl-table> 【❌ 错误】 <sl-table :data-source="rows" :row-selection="sel"></sl-table> - 数字类型属性使用 camelCase 不需 (如
.prop);字符串/布尔属性必须用 camelCase(如:pageSize="20"、rowKey="id"、showHeader),禁止 kebab-case(如simpleMode、row-key)show-header
- 属性绑定:
- TypeScript:推荐使用
<script setup lang="ts">
This project is based on Vue 3, and the following basic principles must be followed:
- Composition API: Uniformly use syntax, forbid using Options API (
<script setup>)export default { data(), methods, computed, watch } - Reactivity: Use /
ref()to declare reactive states, forbid usingreactive(). When passing complex data (objects/arrays) to Web Components, since the underlying layer needs to detect reference changes, absolutely forbid in-place modifications likethisorpush, and must trigger rendering by reassigning to generate a new reference (e.g.,splice).data.value = [...data.value, new] - Lifecycle: Use Composition API hooks such as /
onMounted()onUnmounted() - Template Syntax:
- Property Binding:
:prop="value" - Event Binding: (Shoelace components use the
@sl-change="handler"prefix)@sl-* - Passing object/array properties to Web Components: Must use camelCase + modifier:
.prophtml【✅ Correct】 <sl-table :dataSource.prop="rows" :columns.prop="cols" :rowSelection.prop="sel"></sl-table> 【❌ Wrong】 <sl-table :data-source="rows" :row-selection="sel"></sl-table> - Numeric type properties use camelCase without (e.g.,
.prop); string/boolean properties must use camelCase (e.g.,:pageSize="20",rowKey="id",showHeader), forbid kebab-case (e.g.,simpleMode,row-key)show-header
- Property Binding:
- TypeScript: Recommended to use
<script setup lang="ts">
3. 标准工作流 (Workflow)
3. Standard Workflow (Workflow)
-
新建组件:
- 必须使用 CLI 工具,严禁手工创建文件:
bash
kd project create [组件名] --type kwc - 组件命名遵循 。
PascalCase
- 必须使用 CLI 工具,严禁手工创建文件:
-
代码实现与修改:
- 学习:优先参考 。
app/kwc/exampleComponent - 严格合规:代码必须符合本 Skill 目录下的 中的所有约束(导入规范、事件绑定等)。
rule.md - Shoelace 集成:涉及 Shoelace 组件时,确保从 correct path 导入。
- 学习:优先参考
-
验证与交付:
- 按项目入口更新 引用。
app/kwc/main* - 运行 进行验证。
npm run dev
- 按项目入口更新
-
Create New Component:
- Must use CLI tool, manual file creation is strictly prohibited:
bash
kd project create [component-name] --type kwc - Component naming follows .
PascalCase
- Must use CLI tool, manual file creation is strictly prohibited:
-
Code Implementation and Modification:
- Learning: Prioritize referencing .
app/kwc/exampleComponent - Strict Compliance: Code must comply with all constraints in rule.md in this Skill directory (import specifications, event binding, etc.).
- Shoelace Integration: When involving Shoelace components, ensure import from the correct path.
- Learning: Prioritize referencing
-
Verification and Delivery:
- Update references according to the project entry.
app/kwc/main* - Run for verification.
npm run dev
- Update
4. 关键约束摘要 (详细请见本 Skill 目录下的 rule.md)
4. Key Constraint Summary (See rule.md in this Skill directory for details)
- 导入:
import '@kdcloudjs/shoelace/dist/components/input/input.js'; - 模板:使用 (kebab-case)。
<sl-input> - 事件:使用 绑定。
@sl-change - CSS:样式必须使用 Shoelace Design Token(、
var(--sl-color-*)、var(--sl-spacing-*)、var(--sl-font-size-*)),禁止硬编码 hex 色值和 px 数值。详见var(--sl-border-radius-*)。./reference/css-design-tokens.md
- Import:
import '@kdcloudjs/shoelace/dist/components/input/input.js'; - Template: Use (kebab-case).
<sl-input> - Events: Use for binding.
@sl-change - CSS: Styles must use Shoelace Design Token (,
var(--sl-color-*),var(--sl-spacing-*),var(--sl-font-size-*)), hardcoding hex color values and px numbers is forbidden. Seevar(--sl-border-radius-*)for details../reference/css-design-tokens.md
5. 常用资源
5. Common Resources
- 扩展组件文档(位于本 Skill 的 目录下):
reference/- Table:
reference/table/index.md - DatePicker:
reference/datepicker/index.md - TimePicker:
reference/sl-timepicker.md - Pagination:
reference/sl-pagination.md - 使用前必须阅读相应文档。
- Table:
- 标准组件文档:https://shoelace.style/
- Extended Component Documentation (located in the directory of this Skill):
reference/- Table:
reference/table/index.md - DatePicker:
reference/datepicker/index.md - TimePicker:
reference/sl-timepicker.md - Pagination:
reference/sl-pagination.md - Must read the corresponding documentation before use.
- Table:
- Standard Component Documentation: https://shoelace.style/
6. 输出检查清单
6. Output Checklist
提交代码前,请自查:
- 使用 Vue 3 Composition API (),未使用 Options API
<script setup> - 新建组件使用了
kd project create [组件名] --type kwc - 已阅读并遵守本 Skill 目录下的 中的所有约束
rule.md - 导入了所有使用的 Web Components
- 模板标签为 kebab-case
- 事件使用
@sl-* - 未运行任何 ESLint/Prettier 修复命令,并忽略了所有 ESLint 格式报错
Before submitting code, self-check:
- Used Vue 3 Composition API (), did not use Options API
<script setup> - Used for new components
kd project create [component-name] --type kwc - Read and complied with all constraints in rule.md in this Skill directory
- Imported all used Web Components
- Template tags are kebab-case
- Events use
@sl-* - Did not run any ESLint/Prettier fix commands, and ignored all ESLint format errors