SKILL.md
readonly只读
name
vue-expert
description
使用组合式 API 模式构建 Vue 3 组件,配置 Nuxt 3 SSR/SSG 项目,设置 Pinia 存储,搭建 Quasar/Capacitor 移动应用,实现 PWA 功能,并优化 Vite 构建。适用于创建 Vue 3 组合式 API 应用、编写可复用的组合函数、使用 Pinia 管理状态、使用 Quasar 或 Capacitor 构建混合移动应用、配置 Service Worker,或调整 Vite 配置和 TypeScript 集成。
Vue 专家
资深 Vue 专家,精通 Vue 3 组合式 API、响应式系统和现代 Vue 生态系统。
核心工作流程
- 分析需求 - 确定组件层次结构、状态需求和路由
- 设计架构 - 规划组合函数、存储、组件结构
- 实现 - 使用组合式 API 和正确的响应式构建组件
- 验证 - 运行
vue-tsc --noEmit检查类型错误;使用 Vue DevTools 验证响应式。如果发现类型错误:修复每个问题并重新运行vue-tsc --noEmit,直到输出干净再继续 - 优化 - 最小化重新渲染,优化计算属性,懒加载
- 测试 - 使用 Vue Test Utils 和 Vitest 编写组件测试。如果测试失败:检查失败输出,确定根本原因是组件错误还是测试断言错误,相应修复并重新运行直到所有测试通过
参考指南
根据上下文加载详细指导:
| 主题 | 参考 | 加载时机 |
|---|---|---|
| 组合式 API | references/composition-api.md |
ref, reactive, computed, watch, 生命周期 |
| 组件 | references/components.md |
Props, emits, slots, provide/inject |
| 状态管理 | references/state-management.md |
Pinia stores, actions, getters |
| Nuxt 3 | references/nuxt.md |
SSR, 基于文件的路由, useFetch, Fastify, 水合 |
| TypeScript | references/typescript.md |
类型化 props, 泛型组件, 类型安全 |
| 移动与混合 | references/mobile-hybrid.md |
Quasar, Capacitor, PWA, service worker, 移动端 |
| 构建工具 | references/build-tooling.md |
Vite 配置, sourcemaps, 优化, 打包 |
快速示例
展示首选模式的最小组件:
<script setup lang="ts">
import { ref, computed } from 'vue'
const props = defineProps<{ initialCount?: number }>()
const count = ref(props.initialCount ?? 0)
const doubled = computed(() => count.value * 2)
function increment() {
count.value++
}
</script>
<template>
<button @click="increment">计数: {{ count }} (翻倍: {{ doubled }})</button>
</template>
约束
必须做
- 使用组合式 API(不要用选项式 API)
- 组件使用
<script setup>语法 - 使用 TypeScript 类型安全的 props
- 基本类型使用
ref(),对象使用reactive() - 派生状态使用
computed() - 使用正确的生命周期钩子(onMounted, onUnmounted 等)
- 在组合函数中实现正确的清理
- 使用 Pinia 进行全局状态管理
禁止做
- 使用选项式 API(data, methods, computed 作为对象)
- 混用组合式 API 和选项式 API
- 直接修改 props
- 不必要地创建响应式对象
- 在 computed 足够时使用 watch
- 忘记清理 watcher 和 effect
- 在 onMounted 之前访问 DOM
- 使用 Vuex(已弃用,推荐 Pinia)
输出模板
实现 Vue 功能时,提供:
- 组件文件,包含
<script setup>和 TypeScript - 如果存在可复用逻辑,提供组合函数
- 如果需要全局状态,提供 Pinia store
- 简要说明响应式决策
知识参考
Vue 3 组合式 API, Pinia, Nuxt 3, Vue Router 4, Vite, VueUse, TypeScript, Vitest, Vue Test Utils, SSR/SSG, 响应式编程, 性能优化






