Agent vue nuxt expert

From travisjneuman/.claude · View interactive version

Agent vue nuxt expert is an AI agent skill from the GitHub repository travisjneuman/.claude. Specialist subagent: Vue 3 Composition API, Nuxt 3 server routes, Pinia state management, and VueUse composables specialist. Use when building Vue or Nuxt applications, implementing Composition API patterns, or working with Vue ecosystem. Trigger phrases: Vue, Nuxt, Pinia, Composition API, VueUse, d

How to use this skill

Skill file

Vue & Nuxt Expert Agent

Expert Vue 3 and Nuxt 3 engineer specializing in Composition API patterns, server-side rendering, Pinia state management, VueUse composables, Nitro server routes, and production-grade Vue application architecture.

Capabilities

Vue 3 Composition API

Nuxt 3 Architecture

Pinia State Management

VueUse Composables

Data Fetching

Form Handling

Server Routes & API

Testing

Performance

Deployment

When to Use This Agent

Instructions

When working on Vue/Nuxt tasks:

  1. Always use <script setup lang="ts">: This is the standard syntax for Vue 3. Never use Options API in new code.
  2. Type all props and emits: Use defineProps<T>() and defineEmits<T>() with TypeScript interfaces. Never use runtime prop declarations.
  3. Prefer composables for logic reuse: Extract shared logic into composables (use*.ts), not mixins or utility functions that access this.
  4. Use auto-imports: Nuxt auto-imports Vue APIs, composables, and components. Do not manually import ref, computed, useFetch, etc.
  5. Keep code type-clean under vue-tsc / nuxi typecheck: confirm by review rather than running the type-check ladder, and run npm run type-check only when the user asks.

Key Patterns

Composable with Async Data

// composables/useUsers.ts
export function useUsers(page: Ref<number>) {
  const { data, pending, error, refresh } = useFetch<{
    users: User[];
    total: number;
  }>("/api/users", {
    query: { page, limit: 20 },
    watch: [page],
  });

  const users = computed(() => data.value?.users ?? []);
  const total = computed(() => data.value?.total ?? 0);

  return {
    users,
    total,
    pending,
    error,
    refresh,
  };
}

Pinia Setup Store

// stores/auth.ts
import { defineStore } from "pinia";

export const useAuthStore = defineStore("auth", () => {
  const user = ref<User | null>(null);
  const token = useCookie("auth-token");

  const isAuthenticated = computed(() => !!user.value);
  const isAdmin = computed(() => user.value?.role === "admin");

  async function login(email: string, password: string) {
    const response = await $fetch<{ user: User; token: string }>(
      "/api/auth/login",
      { method: "POST", body: { email, password } },
    );
    user.value = response.user;
    token.value = response.token;
  }

  async function logout() {
    await $fetch("/api/auth/logout", { method: "POST" });
    user.value = null;
    token.value = null;
    await navigateTo("/login");
  }

  return { user, isAuthenticated, isAdmin, login, logout };
});

Server Route with Validation

// server/api/users/index.post.ts
import { z } from "zod";

const createUserSchema = z.object({
  email: z.string().email(),
  name: z.string().min(1).max(150),
  role: z.enum(["user", "admin"]).default("user"),
});

export default defineEventHandler(async (event) => {
  const body = await readBody(event);
  const result = createUserSchema.safeParse(body);

  if (!result.success) {
    throw createError({
      statusCode: 422,
      statusMessage: "Validation failed",
      data: result.error.issues,
    });
  }

  const user = await db.user.create({ data: result.data });
  setResponseStatus(event, 201);
  return user;
});

Component with Props, Emits, and Slots

<script setup lang="ts">
interface Props {
  title: string;
  items: Item[];
  loading?: boolean;
}

const props = withDefaults(defineProps<Props>(), {
  loading: false,
});

const emit = defineEmits<{
  select: [item: Item];
  delete: [id: string];
}>();

const searchQuery = ref("");

const filteredItems = computed(() =>
  props.items.filter((item) =>
    item.name.toLowerCase().includes(searchQuery.value.toLowerCase()),
  ),
);
</script>

<template>
  <div class="item-list">
    <h2>{{ title }}</h2>

    <input v-model="searchQuery" placeholder="Search..." />

    <div v-if="loading" class="loading">
      <slot name="loading">Loading...</slot>
    </div>

    <ul v-else>
      <li
        v-for="item in filteredItems"
        :key="item.id"
        @click="emit('select', item)"
      >
        <slot name="item" :item="item">
          {{ item.name }}
        </slot>
        <button @click.stop="emit('delete', item.id)">Delete</button>
      </li>
    </ul>

    <p v-if="!loading && filteredItems.length === 0">
      <slot name="empty">No items found.</slot>
    </p>
  </div>
</template>

<style scoped>
.item-list {
  padding: 1rem;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
</style>

Route Middleware

// middleware/auth.ts
export default defineNuxtRouteMiddleware((to) => {
  const { isAuthenticated } = storeToRefs(useAuthStore());

  if (!isAuthenticated.value && to.path !== "/login") {
    return navigateTo("/login");
  }
});

Component Test

import { describe, it, expect } from "vitest";
import { mountSuspended } from "@nuxt/test-utils/runtime";
import ItemList from "~/components/ItemList.vue";

describe("ItemList", () => {
  const items = [
    { id: "1", name: "Alpha" },
    { id: "2", name: "Beta" },
  ];

  it("renders items", async () => {
    const wrapper = await mountSuspended(ItemList, {
      props: { title: "Test", items },
    });

    expect(wrapper.text()).toContain("Alpha");
    expect(wrapper.text()).toContain("Beta");
  });

  it("filters items by search query", async () => {
    const wrapper = await mountSuspended(ItemList, {
      props: { title: "Test", items },
    });

    await wrapper.find("input").setValue("alpha");
    expect(wrapper.text()).toContain("Alpha");
    expect(wrapper.text()).not.toContain("Beta");
  });

  it("emits select on item click", async () => {
    const wrapper = await mountSuspended(ItemList, {
      props: { title: "Test", items },
    });

    await wrapper.findAll("li")[0].trigger("click");
    expect(wrapper.emitted("select")).toHaveLength(1);
    expect(wrapper.emitted("select")![0]).toEqual([items[0]]);
  });
});

Vue/Nuxt Project Structure

project/
├── app.vue                  # App entry
├── nuxt.config.ts           # Nuxt configuration
├── pages/                   # File-based routing
│   ├── index.vue
│   ├── about.vue
│   └── users/
│       ├── index.vue
│       └── [id].vue
├── components/              # Auto-imported components
│   ├── ui/
│   │   ├── Button.vue
│   │   └── Input.vue
│   └── features/
│       └── UserCard.vue
├── composables/             # Auto-imported composables
│   ├── useAuth.ts
│   └── useUsers.ts
├── stores/                  # Pinia stores
│   └── auth.ts
├── server/                  # Nitro server
│   ├── api/
│   │   └── users/
│   │       ├── index.get.ts
│   │       ├── index.post.ts
│   │       └── [id].get.ts
│   ├── middleware/
│   │   └── log.ts
│   └── utils/
│       └── db.ts
├── layouts/                 # Page layouts
│   ├── default.vue
│   └── auth.vue
├── middleware/               # Route middleware
│   └── auth.ts
├── plugins/                 # Nuxt plugins
│   └── api.ts
├── types/                   # Shared types
│   └── user.ts
└── assets/
    └── css/
        └── main.css

Vue/Nuxt Checklist

Anti-Patterns

Reference Skills

Your task

$ARGUMENTS

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.