web-vue
Vue 3: Composition API script setup, Pinia, Vue Router 4, SFCs, Vite, Nuxt 3
What this skill does
# web-vue
## Purpose
This skill provides tools for building modern Vue 3 applications using the Composition API for reactive logic, Pinia for state management, Vue Router 4 for navigation, Single File Components (SFCs) for modular development, Vite for fast bundling, and Nuxt 3 for server-side rendering and SEO optimization.
## When to Use
Use this skill for creating interactive web apps with reactive UIs, such as dashboards, e-commerce sites, or single-page applications (SPAs). Apply it when you need efficient state handling, routing, or SSR, especially in projects requiring quick development cycles with Vite.
## Key Capabilities
- Composition API: Use `setup()` in SFCs for reactive variables, e.g., `const count = ref(0);` to create a reactive number.
- Pinia: Define stores with `defineStore('main', { state: () => ({ count: 0 }), actions: { increment() { this.count++ } })` for global state.
- Vue Router 4: Set up routes via `createRouter({ history: createWebHistory(), routes: [{ path: '/', component: Home }] })`.
- SFCs: Structure components in .vue files with `<script setup>`, `<template>`, and `<style>` sections.
- Vite: Build projects with `vite build --mode production` for optimized outputs.
- Nuxt 3: Enable SSR with `nuxi generate` for static site generation from Vue apps.
## Usage Patterns
To create a reactive counter component, import `ref` from Vue and use it in `<script setup>`:
```vue
<script setup>
import { ref } from 'vue';
const count = ref(0);
function increment() { count.value++; }
</script>
<template><button @click="increment">{{ count }}</button></template>
```
For routing, integrate Vue Router by creating a router instance and mounting it:
```js
import { createRouter, createWebHistory } from 'vue-router';
const router = createRouter({ history: createWebHistory(), routes: [] });
app.use(router);
```
Set up Pinia in main.js: `app.use(createPinia());` and access stores via `useStore()` in components.
## Common Commands/API
- Vite CLI: Run `vite` for dev server, `vite build --base /app/` to specify base path, or `vite preview` for local testing.
- Nuxt 3 CLI: Use `nuxi dev` for development, `nuxi build` for production builds, or `nuxi generate` for static exports.
- Vue API: Call `ref(value)` to create reactive references, `reactive(object)` for proxy objects, or `computed(() => expression)` for derived state.
- Pinia API: Define stores with `defineStore('id', { state, getters, actions })`, access via `const store = useStore('id')`.
- Vue Router API: Use `router.push('/path')` for navigation, or configure guards with `beforeEach((to, from, next) => { next(); })`.
If API keys are needed (e.g., for external services in Nuxt), set them via environment variables like `$NUXT_PUBLIC_API_KEY` in .env files.
## Integration Notes
Integrate Pinia into a Vue app by importing and using it in main.js: `import { createPinia } from 'pinia'; app.use(createPinia());`. For Vue Router, add it after Pinia: `import { createRouter } from 'vue-router'; app.use(router);`. When using Vite, configure in vite.config.js with modules like:
```js
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [vue()],
resolve: { alias: { '@': '/src' } },
});
```
For Nuxt 3, extend the Nuxt config in nuxt.config.ts:
```ts
export default defineNuxtConfig({
modules: ['@pinia/nuxt'],
router: { options: {} },
});
```
Ensure dependencies are installed via `npm install vue@3 pinia vue-router@4 vite nuxt@3`.
## Error Handling
Handle common errors like missing dependencies by checking npm logs and running `npm install`. For reactive issues in Composition API, use `.value` on refs, e.g., if `count` is undefined, ensure it's defined in setup. Vue Router errors (e.g., duplicate routes) show in console; fix by validating routes array. In Vite, if builds fail with "Module not found", verify paths in imports or use `vite build --debug` for details. For Nuxt, catch SSR errors in serverMiddleware or use try-catch in asyncData:
```js
async asyncData() {
try { const data = await fetchData(); return { data }; }
catch (error) { console.error(error); return { error: 'Fetch failed' }; }
}
```
## Concrete Usage Examples
1. Build a simple Vue 3 app with a counter and routing: Create a new Vite project with `npm create vite@latest my-app -- --template vue`, add Pinia via `npm install pinia`, set up a store, and define routes in router/index.js. Then, in App.vue, use the store and router links.
2. Develop a Nuxt 3 app with SSR: Start with `npx nuxi init my-nuxt-app`, install dependencies like `npm install @pinia/nuxt`, create a Pinia store in stores/, and use it in pages/index.vue. Build for production with `nuxi build`, then deploy.
## Graph Relationships
- Related to cluster: web-dev
- Shares tags: vue, components, web
- Connected skills: Other web-dev skills like those for React or general web frameworks.
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.