← 返回 Skills 市场
acanzaima

vue-composition-api-best-practices

作者 阿灿在吗 · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
20
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install vue-composition-api-best-practices
功能描述
Vue 3 组合式 API 与 <script setup> 最佳实践。涵盖代码组织、useXxx 模式、组合式函数设计、Store 集成、响应性优化及功能提取。
使用说明 (SKILL.md)

\r \r Vue 3 组合式 API 与 \x3Cscript setup>、TypeScript 集成及代码组织模式的最佳实践。\r \r

版本兼容性\r

\r 本技能面向 Vue 3.3+,部分功能需要更高的次版本号:\r \r | 特性 | 最低版本 | 参考 |\r |---------|:---:|---|\r | defineOptions | 3.3+ | script-setup |\r | toValue() | 3.3+ | script-setup |\r | defineModel | 3.4+ | script-setup |\r | watch 搭配 once 选项 | 3.4+ | reactivity |\r | useTemplateRef() | 3.5+ | script-setup |\r | useId() | 3.5+ | script-setup |\r | onWatcherCleanup() | 3.5+ | reactivity |\r \r

快速决策表\r

\r | 问题 | 参考阅读 |\r |---------|-------------|\r | 我的 \x3Cscript setup> 很乱,难以浏览 | SFC 代码组织 |\r | 某个功能的逻辑分散在很多行中 | useXxx 函数模式 |\r | 相同逻辑在多个组件中重复 | 功能提取 |\r | 两个功能相互影响,但不知道正确的处理模式 | 跨功能依赖 |\r | Props/emits 类型安全、defineModel 使用 | script setup 最佳实践 |\r | 在 hooks/工具函数/插件中无法访问 Store | 组件外 Store 访问 |\r | 如何组织新的组合式函数文件 | 组合式函数设计模式 |\r | 页面感觉慢,可能是响应性问题 | 响应性与性能 |\r | 如何测试组合式函数 | 组合式函数测试 |\r | 类型安全的 provide/inject | script setup - Provide/Inject |\r \r

代码组织\r

TypeScript 与 Script Setup\r

Store 集成\r

组合式函数设计\r

响应性与性能\r

测试\r

速查表\r

\r

SFC 代码组织顺序(11 步)\r

\r

1. defineOptions     → 组件名称\r
2. defineProps       → Props 类型声明\r
3. defineModel       → 双向绑定(3.4+)\r
4. inject            → 注入依赖\r
5. defineEmits       → 事件类型声明\r
6. Store 声明         → useXxxStore()\r
7. 外部 hooks         → useI18n()、useDesign() 等\r
8. 功能声明           → const { ... } = useFeature()\r
9. provide           → 提供依赖\r
10. defineExpose     → 暴露公共 API\r
11. 功能实现          → function useFeature() {}\r
```\r
\r
### 响应式 API 选择\r
\r
```\r
基本类型       → ref\r
需要深层响应    → ref\r
大型对象/动态组件 → shallowRef\r
不需要重新赋值   → reactive(谨慎使用)\r
永不响应式      → markRaw + shallowRef\r
```\r
\r
### Store 访问规则\r
\r
```\r
组件内 (\x3Cscript setup>)  → useAppStore()\r
组件外 (hooks/utils/plugins) → useAppStoreWithOut()\r
解构保持响应式            → storeToRefs(store)\r
```\r
\r
### 反模式 TOP 5\r
\r
| # | 反模式 | 正确做法 |\r
|---|--------|---------|\r
| 1 | 解构 props → 丢失响应式 | `toRefs(props)` 或直接用 `props.xxx` |\r
| 2 | 组件外用 `useXxxStore()` | 用 `useXxxStoreWithOut()` |\r
| 3 | `ref` 用于动态组件/大对象 | 用 `shallowRef` |\r
| 4 | 混用 Options API + script setup | 只选一种风格 |\r
| 5 | 事件监听不清理 | `onUnmounted` 中移除 / 使用 VueUse 的 `useEventListener` |\r
\r
### 依赖模式速查\r
\r
| 场景 | 推荐模式 |\r
|------|---------|\r
| 父子组件通信 | Props + Emits |\r
| 兄弟功能交互 | 回调参数(`onXxxChange`) |\r
| 跨层级多对多 | 事件总线(`useEmitt`) |\r
| 共享状态 | Store 桥接组合式函数 |\r
| 功能编排 | 组合式函数编排模式 |\r
安全使用建议
This appears safe to install as a documentation-style skill. Treat its code snippets as guidance to adapt carefully in your own Vue project, especially examples involving browser storage, event listeners, or JSONP, but the skill itself does not request sensitive access or execute code.
功能分析
Type: OpenClaw Skill Name: vue-composition-api-best-practices Version: 1.0.0 The skill bundle is a comprehensive educational resource providing best practices for Vue 3 Composition API and <script setup>. It contains detailed documentation and standard code snippets for organizing SFCs, designing composables, and managing state with Pinia. No evidence of malicious intent, data exfiltration, or harmful prompt injection was found; the content is strictly aligned with its stated purpose of improving Vue 3 development patterns.
能力标签
crypto
能力评估
Purpose & Capability
The artifacts consistently describe Vue 3 Composition API, script setup, composables, Pinia store patterns, reactivity, and code-organization guidance.
Instruction Scope
The instructions are scoped to software-development best practices and reference local markdown files; they do not ask the agent to override user intent, run commands, modify accounts, or perform autonomous actions.
Install Mechanism
There is no install specification and no code files; the registry describes this as an instruction-only skill.
Credentials
No binaries, environment variables, credentials, config paths, OS restrictions, or network/runtime permissions are requested. Browser APIs and storage appear only in instructional Vue code examples.
Persistence & Privilege
The skill itself does not establish persistence, background execution, privileged access, or credential use. Example snippets discuss app-level localStorage/IndexedDB/event listeners as Vue patterns, not skill behavior.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install vue-composition-api-best-practices
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /vue-composition-api-best-practices 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release with best practices and decision guides for Vue 3 Composition API and <script setup>: - Covers code organization, useXxx patterns, composable function design, Store integration, reactivity optimization, and feature extraction. - Includes quick reference tables for component structure, reactive API choices, Store access, and common anti-patterns. - Provides fast decision guides for typical composition API challenges. - Explains integration with TypeScript, Pinia Store, and testing composables with Vitest.
元数据
Slug vue-composition-api-best-practices
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

vue-composition-api-best-practices 是什么?

Vue 3 组合式 API 与 <script setup> 最佳实践。涵盖代码组织、useXxx 模式、组合式函数设计、Store 集成、响应性优化及功能提取。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 20 次。

如何安装 vue-composition-api-best-practices?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install vue-composition-api-best-practices」即可一键安装,无需额外配置。

vue-composition-api-best-practices 是免费的吗?

是的,vue-composition-api-best-practices 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

vue-composition-api-best-practices 支持哪些平台?

vue-composition-api-best-practices 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 vue-composition-api-best-practices?

由 阿灿在吗(@acanzaima)开发并维护,当前版本 v1.0.0。

💬 留言讨论