--- name: form-vue description: Production-ready Vue form patterns using VeeValidate (default) or Vuelidate with Zod integration. Use when building forms in Vue 3 applications with Composition API. --- # Form Vue Production Vue 3 form patterns. Default stack: **VeeValidate + Zod**. ## Quick Start ```bash npm install vee-validate @vee-validate/zod zod ``` ```vue ``` ## When to Use Which | Criteria | VeeValidate | Vuelidate | |----------|-------------|-----------| | API Style | Declarative (schema) | Imperative (rules) | | Zod Integration | ✅ Native adapter | Manual | | Bundle Size | ~15KB | ~10KB | | Component Support | ✅ Built-in Field/Form | Manual binding | | Async Validation | ✅ Built-in | ✅ Built-in | | Cross-field Validation | ✅ Easy | More manual | | Learning Curve | Low | Medium | **Default: VeeValidate** — Better DX, native Zod support. **Use Vuelidate when:** - Need extremely fine-grained control - Existing Vuelidate codebase - Prefer imperative validation style ## VeeValidate Patterns ### Basic Form with Composition API ```vue ``` ### Reusable FormField Component ```vue ``` ### Using FormField Component ```vue ``` ### Form with Initial Values ```vue ``` ### Async Validation (Username Check) ```vue ``` ### Cross-Field Validation (Password Confirmation) ```vue ``` ### Field Arrays (Dynamic Fields) ```vue ``` ## Vuelidate Patterns ### Basic Form ```vue ``` ### Vuelidate with Zod ```vue ``` ## Shared Zod Schemas ```typescript // schemas/index.ts (shared between React and Vue) import { z } from 'zod'; export const loginSchema = z.object({ email: z.string().min(1, 'Email is required').email('Invalid email'), password: z.string().min(1, 'Password is required'), rememberMe: z.boolean().optional().default(false) }); export type LoginFormData = z.infer; // VeeValidate usage import { toTypedSchema } from '@vee-validate/zod'; const veeSchema = toTypedSchema(loginSchema); // React Hook Form usage import { zodResolver } from '@hookform/resolvers/zod'; const rhfResolver = zodResolver(loginSchema); ``` ## File Structure ``` form-vue/ ├── SKILL.md ├── references/ │ ├── veevalidate-patterns.md # VeeValidate deep-dive │ └── vuelidate-patterns.md # Vuelidate deep-dive └── scripts/ ├── veevalidate-form.vue # VeeValidate patterns ├── vuelidate-form.vue # Vuelidate patterns ├── form-field.vue # Reusable field component └── schemas/ # Shared with form-validation ├── auth.ts ├── profile.ts └── payment.ts ``` ## Reference - `references/veevalidate-patterns.md` — Complete VeeValidate patterns - `references/vuelidate-patterns.md` — Vuelidate patterns