fn
useField
v0.0.16testeddemoBind a single field by path. When rendered under a {@link useForm}(or given an explicit `form`), it reads/writes that form's state; otherwise it runs standalone with its own value, errors, and validation. Returns a writable `value`, reactive errors/meta, blur/change handlers, and `attrs` to spread.
Examples
ts
// Within a useForm() component
const { value, errorMessage, attrs } = useField('email', {
validate: (v) => v.includes('@') || 'Invalid email',
});
// <input v-model="value" v-bind="attrs">ts
// Standalone (no form ancestor)
const { value, errors } = useField('search', { initialValue: '', schema });Demo
Loading demo…
Signature
ts
export function useField<T = any>(
path: MaybeRefOrGetter<string>,
options: UseFieldOptions<T> ={ ... }Type Parameters
T= anyParameters
| Parameter | Type | Description |
|---|---|---|
path | MaybeRefOrGetter<string> | The dotted field path (reactive allowed) |
options? | UseFieldOptions<T, any> | Validators, schema, trigger, explicit form, or standalone `initialValue` |
Returns
UseFieldReturn<T>The field's reactive value, errors, meta, and handlers