用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/TencentBlueKing/blueking-apigateway --skill pinia-setup命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| id | pinia-setup |
| name | pinia-setup |
| description | 基于 Pinia 的全局状态管理规范,包含 UserStore、AppStore 的标准定义 |
推荐使用 Setup Store 语法(类似 Composition API),比 Options API 更灵活。
// src/store/user.ts
import { defineStore } from 'pinia';
import { ref } from 'vue';
export const useUserStore = defineStore('user', () => {
const userInfo = ref(null);
const loading = ref(false);
const fetchUserInfo = async () => {
if (userInfo.value) return userInfo.value;
loading.value = true;
try {
userInfo.value = await http.get('/user/info');
} finally {
loading.value = false;
}
};
return { userInfo, loading, fetchUserInfo };
});
<script setup lang="ts">
import { useUserStore } from '@/store/user';
import { storeToRefs } from 'pinia';
const userStore = useUserStore();
// 使用 storeToRefs 保持响应性
const { userInfo, loading } = storeToRefs(userStore);
// Action 直接调用
userStore.fetchUserInfo();
</script>
| 错误 | 解决 |
|---|---|
| 解构丢失响应性 | 用 storeToRefs() |
| 多次实例化 | Store 单例,直接 useXxxStore() |
| 资源 | URI |
|---|---|
| 完整 Store 模板 | ./assets/store-template.ts |
./assets/store-template.ts根据 SKILL.md 中的 IF-THEN 规则判断是否需要加载