依据WCAG 2.2设计和检查Web、iOS及Android界面,核查读屏标签、键盘操作、配色对比度和操作目标尺寸,使界面支持辅助技术。
- 为纯图标按钮添加说明
- 检查键盘操作与模态框焦点
- 检查对比度与操作目标尺寸
为Vue.js 3和Nuxt界面实现提供从组件设计、共享状态管理到页面导航与测试的指导。通过具体示例检查代码组织和数据更新方式,也涵盖Nuxt数据获取与服务端渲染。
Vue.js 3 Composition API patterns, component architecture, reactivity best practices, Pinia state management, Vue Router navigation, and Nuxt SSR patterns. Activates for Vue, Nuxt, Vite, or Pinia projects. Use when building or reviewing Vue 3, Nuxt, or Pinia code — Composition API, reactivity, or router navigation.
本技能汇集了实现和审查Vue.js 3与Nuxt界面的设计指导。内容包括使用Composition API组织组件、提取可复用逻辑,以及让数据变化反映到界面的响应式机制。还提供Pinia共享数据管理、Vue Router页面导航、渲染性能和测试示例,并涵盖Nuxt的数据获取与服务端页面生成。
适合.vue文件变得复杂,或多个页面需要共享数据和逻辑的情况。可以检查组件职责划分、数据更新流程,以及侦听逻辑的清理方式,也可以用来确认Vue和Nuxt在写法上的差异。
主要面向Vue.js 3。defineModel()要求Vue 3.4及以上版本,useTemplateRef()等部分示例要求Vue 3.5及以上版本。测试示例涉及Vitest、Vue Test Utils、@pinia/testing和Playwright。
本介绍由 AI(OpenAI Codex)根据公开的 SKILL.md 撰写。准确的规格请查看下方原文。
AI 仅根据 SKILL.md 的内容,从 4 个方面进行了评估。星标数和热度不计入评估。
总分按每项 A=25 分、B=15 分、C=5 分相加。 由 AI(OpenAI Codex)于 2026年10月19日 评估。仅供参考,安装前请同时查看原文。
安装前可以查看交给 AI 代理的指令内容。
Comprehensive guide for Vue.js 3 development using Composition API (<script setup>), covering component design, reactivity, state management, routing, testing, and SSR patterns. Nuxt-specific guidance is included where it differs from vanilla Vue.
Activate this skill when:
.vue files).src/
├── api/ # API client and endpoint definitions
├── assets/ # Static assets (images, fonts, icons)
├── components/ # Shared/reusable components
│ ├── base/ # Base UI primitives (Button, Input, Modal)
│ └── features/ # Feature-specific shared components
├── composables/ # Reusable Composition API logic
├── layouts/ # Page layouts (optional)
├── pages/ # Route-level page components
├── router/ # Vue Router configuration
├── stores/ # Pinia stores
├── types/ # TypeScript type definitions
├── utils/ # Pure utility functions
└── App.vue # Root component
| Convention | When to Use |
|---|---|
PascalCase.vue | All components (enforced by vue/multi-word-component-names) |
useCamelCase.ts | Composables |
camelCase.ts | Utilities, API clients, types |
kebab-case directories | Route segments, feature folders |
<script setup lang="ts">
// 1. Imports (vue → ecosystem → absolute → relative)
// 2. Props & Emits & Slots
// 3. Composables
// 4. Local state (ref/reactive)
// 5. Computed properties
// 6. Methods
// 7. Watchers
// 8. Lifecycle hooks
</script>
<template>
<!-- Template content -->
</template>
<style scoped>
/* Scoped styles */
</style>
// Type-based props with defaults
interface Props {
label: string;
variant?: "primary" | "secondary";
disabled?: boolean;
items: Item[];
}
const props = withDefaults(defineProps<Props>(), {
variant: "primary",
disabled: false,
});
type, and required/default where appropriate.isXxx, hasXxx, canXxx.defineModel() (Vue 3.4+) or modelValue + update:modelValue.const emit = defineEmits<{
submit: [];
"update:modelValue": [value: string];
select: [id: string, index: number];
}>();
@update:model-value).emit("update:modelValue", val)).// composables/useDebounce.ts
export function useDebounce<T>(value: MaybeRef<T>, delay: number): Ref<T> {
const debounced = ref(toValue(value)) as Ref<T>;
let timer: ReturnType<typeof setTimeout>;
watch(
() => toValue(value),
(newVal) => {
clearTimeout(timer);
timer = setTimeout(() => { debounced.value = newVal; }, delay);
}
);
onUnmounted(() => clearTimeout(timer));
return readonly(debounced);
}
use prefix.ref, computed, reactive), never plain primitives.MaybeRef / toRef() / toValue().onUnmounted or watcher onCleanup.Composables replace Vue 2 mixins entirely:
| Pattern | Use Case |
|---|---|
ref() / reactive() | Local component state |
| Props + Emits | Parent-child communication |
| Provide / Inject | Theme, config, plugin API |
| Pinia store | Global, shared, complex state |
| Server state composable | API data with caching (wrap fetch/TanStack Query) |
// stores/useCartStore.ts
export const useCartStore = defineStore("cart", () => {
const items = ref<CartItem[]>([]);
const isLoading = ref(false);
const totalPrice = computed(() =>
items.value.reduce((sum, i) => sum + i.price * i.quantity, 0)
);
const itemCount = computed(() =>
items.value.reduce((sum, i) => sum + i.quantity, 0)
);
async function addItem(productId: string) {
isLoading.value = true;
try {
const item = await fetchProduct(productId);
const existing = items.value.find(i => i.id === item.id);
if (existing) existing.quantity++;
else items.value.push({ ...item, quantity: 1 });
} finally {
isLoading.value = false;
}
}
return { items, isLoading, totalPrice, itemCount, addItem };
});
$patch() for grouped updates.const routes = [
{
path: "/users/:id",
name: "user-detail",
component: () => import("@/pages/UserDetail.vue"), // lazy
props: true, // pass params as props
meta: { requiresAuth: true },
},
];
router.beforeEach((to, from) => {
const { isLoggedIn } = useAuthStore();
if (to.meta.requiresAuth && !isLoggedIn) {
return { name: "login", query: { redirect: to.fullPath } };
}
});
When a component stays mounted but route params change:
const route = useRoute();
const id = computed(() => route.params.id as string);
watch(id, (newId) => fetchItem(newId));
<!-- v-if/v-else-if/v-else -->
<div v-if="isLoading">Loading...</div>
<div v-else-if="error">Error: {{ error }}</div>
<div v-else>{{ content }}</div>
<!-- v-show for frequent toggles -->
<div v-show="isOpen">Toggled content</div>
<!-- v-for with stable keys -->
<div v-for="item in items" :key="item.id">{{ item.name }}</div>
<!-- Computed filtered list (not v-if + v-for on same element) -->
<div v-for="item in activeItems" :key="item.id">{{ item.name }}</div>
<!-- Event handling -->
<form @submit.prevent="handleSubmit">
<button type="submit">Save</button>
</form>
<!-- v-model -->
<input v-model="name" />
<CustomInput v-model="value" v-model:title="title" />
| Technique | When to Use |
|---|---|
v-memo | List items that rarely change |
v-once | Content rendered once and static forever |
shallowRef() | Large data structures replaced wholesale |
shallowReactive() | Only top-level properties are reactive |
v-show over v-if | Frequent visibility toggles |
<KeepAlive :max="10"> | Cache toggled views |
| Lazy routes | () => import(...) for non-critical routes |
Suspense | Async component loading with fallback |
import { mount } from "@vue/test-utils";
import { createPinia, setActivePinia } from "pinia";
import UserCard from "./UserCard.vue";
beforeEach(() => { setActivePinia(createPinia()); });
it("renders and emits", async () => {
const wrapper = mount(UserCard, {
props: { user: { id: "1", name: "Alice" } },
});
expect(wrapper.text()).toContain("Alice");
await wrapper.find("button").trigger("click");
expect(wrapper.emitted("select")![0]).toEqual(["1"]);
});
Nuxt auto-imports ref, computed, watch, useFetch, useAsyncData, etc. Use them directly without importing. For non-Nuxt projects, always import explicitly.
const { data: user, pending, error, refresh } = await useAsyncData(
"user", // unique key for caching
() => $fetch(`/api/users/${id}`),
);
const { data: posts } = await useFetch("/api/posts", {
query: { page: 1 },
key: "posts-page-1", // dedupes requests
});
// server/api/users/[id].ts
export default defineEventHandler(async (event) => {
const { id } = await getValidatedRouterParams(event, z.object({
id: z.string().uuid(),
}).parse);
// ... fetch and return
});
// nuxt.config.ts
export default defineNuxtConfig({
runtimeConfig: {
// server-only
apiSecret: "",
// public (exposed to client)
public: {
apiBase: "https://api.example.com",
},
},
});
Vue 3.5 stabilized reactive props destructure — destructured variables from defineProps() are automatically reactive:
// Vue 3.5+: destructured props are reactive (no need for toRefs)
const { count = 0, msg = "hello" } = defineProps<{
count?: number;
msg?: string;
}>();
// Limitation: cannot watch destructured prop directly
watch(() => count, (newVal) => { ... }); // PASS getter required
useTemplateRef()Replace name-matched plain refs with useTemplateRef() for template references:
import { useTemplateRef } from "vue";
const inputEl = useTemplateRef<HTMLInputElement>("input");
// "input" matches the ref="input" attribute in template, not the variable name
Supports dynamic ref IDs: useTemplateRef(dynamicRefId).
onWatcherCleanup()Globally importable watcher cleanup API (Vue 3.5+). It must be called synchronously inside the watcher callback:
import { watch, onWatcherCleanup } from "vue";
watch(userId, async (newId) => {
const controller = new AbortController();
onWatcherCleanup(() => controller.abort());
// ... fetch with signal
});
useId()SSR-stable unique ID generation for form elements and accessibility:
import { useId } from "vue";
const id = useId();
defer Teleport<Teleport defer> allows teleporting to targets rendered in the same cycle:
<Teleport defer to="#container">Content</Teleport>
<div id="container"></div>
defineAsyncComponent() now supports hydrate strategy:
import { defineAsyncComponent, hydrateOnVisible } from "vue";
const AsyncComp = defineAsyncComponent({
loader: () => import("./Comp.vue"),
hydrate: hydrateOnVisible(),
});
| Anti-Pattern | Why It's Wrong | The Fix |
|---|---|---|
Destructuring defineProps() (Vue < 3.5) | Captures snapshot, loses reactivity | Access via props.xxx or use toRefs() |
watch() on destructured prop (Vue 3.5+) | Compile-time error — destructured props can't be watched directly | Use getter wrapper: watch(() => count, ...) |
v-if + v-for on same element | Ambiguous execution order | Use computed filtered array |
v-for key = index | Broken state on reorder | Use stable database IDs |
| Mutating props | Violates one-way data flow | Emit events or use v-model |
v-html with user content | XSS vulnerability | Sanitize with DOMPurify |
| Mixins in Vue 3 | Opaque, collision-prone | Replace with composables |
| Module-scope side effects in composable | Shared across instances | Scope in onMounted + onUnmounted |
reactive() for replaceable state | Replacement breaks reactivity | Use ref() instead |
| Watcher without cleanup | Memory leaks, race conditions | Use onCleanup or onWatcherCleanup() (Vue 3.5+) |
| Options API in new Vue 3 code | Ecosystem move to Composition API | Use <script setup> |
| Plain ref for template references | No dynamic ref support, name-matching fragile | Use useTemplateRef() (Vue 3.5+) |
accessibility — ARIA, semantic HTML, focus managementfrontend-patterns — Cross-framework frontend architecturetypescript — TypeScript best practices applied to Vue projectscoding-standards — General code quality standards还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
依据WCAG 2.2设计和检查Web、iOS及Android界面,核查读屏标签、键盘操作、配色对比度和操作目标尺寸,使界面支持辅助技术。
从指令、记忆、工具执行和界面显示等十二个层面排查人工智能代理故障,依据代码和日志梳理原因,按严重程度列出问题并提出修复方案。
用实际开发任务比较多个编程智能体,记录成功率、可获取的API费用、耗时和重复运行的稳定性,为工具选型及更新后的性能评估提供数据。
设计和调整AI智能体使用的工具、输入与返回格式,明确出错后的恢复、重试和停止条件,管理上下文信息量,并以完成率、重试次数和成功任务成本评估改进。
在AI代理反复失败或重复操作时,记录错误与环境前提、排查原因,采取影响有限的恢复操作,并汇总结果和证据,为有依据的重试与交接提供支持。
根据错误信息和执行环境,分析AI代理反复失败或重复操作的原因。通过小范围、可撤销的恢复操作检验假设,并将结果与依据整理成可供交接的报告。