AGENT SKILL
vue3-pinia-composition
Vue 3 组合式 API (<script setup>) 与 Pinia 状态管理架构规范与响应式丢失防御。
- License 许可
- MIT
- 最近更新
- 2026-08-25
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- vue3-pinia-composition
- description
- Vue 3 组合式 API (<script setup>) 与 Pinia 状态管理架构规范与响应式丢失防御。
02 资源文件 1
- 参考文档skill.json1.0 KB
03 SKILL.md 正文
Vue 3 组合式 API 与 Pinia 架构规范
1. 响应式铁律 (Reactivity Rules)
- 优先使用
ref():对于基本类型和普通对象,优先统一使用ref(),避免reactive()在解构赋值时丢失响应性。 - 禁止直接解构 Store:Pinia Store 状态必须使用
storeToRefs()解构,Actions 可直接解构:const userStore = useUserStore(); // ❌ 错误:会破坏响应性 const { profile, isLoggedIn } = userStore; // ✅ 正确:保持响应性 const { profile, isLoggedIn } = storeToRefs(userStore); const { login, logout } = userStore; // actions 保持引用 - 函数式 Setup Store:Pinia 推荐采用与
<script setup>风格一致的函数式写法:
import { defineStore } from 'pinia';
import { ref, computed } from 'vue';
export const useUserStore = defineStore('user', () => {
const token = ref<string | null>(null);
const user = ref<UserProfile | null>(null);
const isAuthenticated = computed(() => !!token.value);
async function fetchCurrentUser() {
if (!token.value) return;
user.value = await api.getUser();
}
function clearSession() {
token.value = null;
user.value = null;
}
return { token, user, isAuthenticated, fetchCurrentUser, clearSession };
});
2. 组合式函数 (Composable) 规范
- 命名统一以
use...开头(如usePagination.ts,useWebSocket.ts)。 - 总是返回纯对象,包含响应式
Ref与操作函数。 - 必须处理组件卸载生命周期,在
onUnmounted()中清理定时器与事件监听器。
04 同仓库更多 Skills
web-page-extractor
网页正文智能提纯与清洗工具。抓取网页并剔除 HTML 标签、脚本与样式,输出高信息密度的 Markdown。
★ 1
restful-api-standard
企业级 RESTful API 设计准则
★ 1
fetch-page
抓取网页并提取标题与正文长度,需要网络权限(默认策略为拒绝,须授权)。
★ 1
api-tester-toolkit
API 接口网络测试与耗时诊断工具包。发起 HTTP GET/POST 请求、统计响应耗时与状态码、检查响应数据。
★ 1
semver-bump
语义化版本号升级:major / minor / patch。
★ 1
translate
中英互译演示实现,内置小词典,用于演示翻译类 skill 的检索与调用。
★ 1