Vue + Zod
TypeScript-first schema validation; the forms' default. This page shows exactly what pickstack adds to a Vue project for Zod: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.
$ npm create pickstack@latest my-app -- --framework vue --modules tanstack-form,zod --yesCustomize in the configurator
Packages it adds
| Package | Version | Type |
|---|---|---|
@tanstack/vue-form | ^1.33.5 | runtime |
zod | ^4.6.7 | runtime |
New files
<script setup lang="ts">
import { useForm } from "@tanstack/vue-form";
import { ref } from "vue";
import { z } from "zod";
const schema = z.object({
email: z.email("Enter a valid email address."),
});
const joined = ref("");
const form = useForm({
defaultValues: { email: "" },
validators: { onSubmit: schema },
onSubmit: ({ value }) => (joined.value = value.email),
});
</script>
<template>
<p v-if="joined" class="text">Thanks, {{ joined }} is on the list.</p>
<form v-else novalidate class="form" @submit.prevent="form.handleSubmit()">
<form.Field name="email">
<template #default="{ field }">
<label class="field">
Email
<input
type="email"
class="input"
:name="field.name"
:value="field.state.value"
@blur="field.handleBlur"
@input="
(event) =>
field.handleChange((event.target as HTMLInputElement).value)
"
/>
<span v-if="field.state.meta.errors[0]" role="alert" class="error">
{{ field.state.meta.errors[0].message }}
</span>
</label>
</template>
</form.Field>
<button type="submit" class="btn">Sign up</button>
</form>
</template>
Changes to existing files
<script setup lang="ts"> import CounterCard from "./components/CounterCard.vue";+import SignupForm from "./components/SignupForm.vue"; </script> <template> <main class="app"> <h1 class="title">my-app</h1> <CounterCard />+ <SignupForm /> </main> </template>
⋯ 87 unchanged lines background: #334155; } +.form {+ display: flex;+ width: 100%;+ max-width: 24rem;+ flex-direction: column;+ gap: 0.75rem;+}+ +.field {+ display: flex;+ flex-direction: column;+ gap: 0.25rem;+ font-size: 0.875rem;+ font-weight: 500;+}+ +.input {+ border: 1px solid #cbd5e1;+ border-radius: 0.5rem;+ padding: 0.5rem 0.75rem;+ font: inherit;+}+ +.error {+ color: #dc2626;+ font-weight: 400;+}+
Project files
.gitignoreREADME.mdenv.d.tsindex.htmlpackage.jsonsrc/App.vuesrc/assets/main.csssrc/components/CounterCard.vuesrc/components/SignupForm.vuesrc/main.tstsconfig.app.jsontsconfig.jsontsconfig.node.jsonvite.config.ts