← Back to Skills Marketplace
acanzaima

vue-composition-api-best-practices

by 阿灿在吗 · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ Security Clean
20
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install vue-composition-api-best-practices
Description
Vue 3 组合式 API 与 <script setup> 最佳实践。涵盖代码组织、useXxx 模式、组合式函数设计、Store 集成、响应性优化及功能提取。
README (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
Usage Guidance
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.
Capability Analysis
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.
Capability Tags
crypto
Capability Assessment
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.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install vue-composition-api-best-practices
  3. After installation, invoke the skill by name or use /vue-composition-api-best-practices
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
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.
Metadata
Slug vue-composition-api-best-practices
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is vue-composition-api-best-practices?

Vue 3 组合式 API 与 <script setup> 最佳实践。涵盖代码组织、useXxx 模式、组合式函数设计、Store 集成、响应性优化及功能提取。 It is an AI Agent Skill for Claude Code / OpenClaw, with 20 downloads so far.

How do I install vue-composition-api-best-practices?

Run "/install vue-composition-api-best-practices" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is vue-composition-api-best-practices free?

Yes, vue-composition-api-best-practices is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does vue-composition-api-best-practices support?

vue-composition-api-best-practices is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created vue-composition-api-best-practices?

It is built and maintained by 阿灿在吗 (@acanzaima); the current version is v1.0.0.

💬 Comments