VfElements
Basic
VfElements is the wrapper component that contains the form's rendered elements. Override the elements slot on VfForm to render VfElements with custom markup around it. The slot receives resolvedSchema which must be passed through to render the elements.
<VfForm :schema="{
name: { type: 'text', label: 'Name' },
email: { type: 'text', label: 'Email' },
}">
<template #content="{ context }">
<VfElements>
<component
v-for="el in context.resolvedSchema"
:is="el.component"
v-bind="el.props"
:key="el.props.name"
/>
</VfElements>
</template>
</VfForm><template>
<VfForm :schema="{
name: { type: 'text', label: 'Name' },
email: { type: 'text', label: 'Email' },
}">
<template #elements="{ resolvedSchema }">
<VfElements>
<component
v-for="el in resolvedSchema"
:is="el.component"
v-bind="el.props"
:key="el.props.name"
/>
</VfElements>
</template>
<VfText name="name" label="Name" />
<VfText name="email" label="Email" />
</VfForm>
</template><script setup lang="ts">
import { defineSchema, defineSlot, useForm } from '@vueform/ui'
import { h, resolveComponent } from 'vue'
const schema = defineSchema({
name: { type: 'text', label: 'Name' },
email: { type: 'text', label: 'Email' },
})
const [MyForm] = useForm({
schema,
slots: {
template: defineSlot('VfForm.template', {
props: ['context'],
setup: ({ context }) => {
return () => {
const VfElements = resolveComponent('VfElements')
return h('div', [
h(VfElements, { resolvedSchema: context.resolvedSchema }, () =>
context.resolvedSchema.map((el: any) =>
h(
typeof el.component === 'string'
? resolveComponent(el.component)
: el.component,
{ ...el.props, key: el.props.name }
)
)
),
])
}
},
}),
},
})
</script>
<template>
<MyForm />
</template>Props
Configure the component's behavior and appearance with these props.
Customization
| Prop | Default | Description |
|---|---|---|
parts | — | Custom DOM attribute overrides for the component's structural parts. |
class | — | CSS classes to apply to the component's root element. |
classes | — | Custom CSS class overrides for the component's structural parts. |
reclass | — | CSS class overrides that replace (rather than merge with) default classes. |
slots | — | Custom Vue components to use for named slots. Every component resolves it through the standard outlets pipeline (see useOutlets). |
presets | — | Named configuration presets to apply to the component. |
template | — | A custom Vue component to use as the template instead of the default. |
component | — | A custom Vue component to render in the component's default slot. |
Context
Reactive properties and methods accessible on the component's Context object.
General
| Name | Description |
|---|---|
props | The resolved component props with defaults applied. |
Layout
| Name | Description |
|---|---|
classes | The resolved CSS class map for the component. |
parts | The resolved DOM attribute overrides for internal elements. |
Events
| Name | Description |
|---|---|
fire() | Fires an event synchronously, invoking before, main, and after listeners in order. |
fireAsync() | Fires an event asynchronously, awaiting each callback and short-circuiting when any returns false. |
on() | Subscribes a callback to a specific event. |
off() | Removes a previously registered event callback. |
onBefore() | Registers a callback that runs before the main event listeners. |
onAfter() | Registers a callback that runs after the main event listeners. |
Events
Events emitted by the component. See Events for details.
| Name | Params | Description |
|---|---|---|
beforeMount | context$ | Emitted before the component is mounted. |
mounted | context$ | Emitted after the component is mounted. |
beforeUnmount | context$ | Emitted before the component is unmounted. |
unmounted | context$ | Emitted after the component is unmounted. |
updated | context$ | Emitted after the component is updated. |
Slots
Named Slots for replacing parts of the component's rendering.
| Name | Scope | Description |
|---|---|---|
template | context | Slot that replaces the entire component rendering. Receives the full component context as a single context prop. |
default | — | Slot for the default content of the elements container. |
Parts
DOM attribute overrides targeting internal elements. See Parts for details.
root
The root elements container.
| Element | <div> |
| Classes | .vf-elements |
Tokens
All the CSS variables that control this component's appearance with default values in the default theme. See Themes & Tokens for details.
:root {
/**
* Component tokens
* -------------------------------------------------------------------------- */
--vf-elements-gutter-stacked-x: calc(var(--vf-gutter) * 0.66);
--vf-elements-gutter-stacked-y: calc(var(--vf-gutter) * 0.66);
--vf-elements-gutter-x: var(--vf-gutter);
--vf-elements-gutter-y: var(--vf-gutter);
}{
/**
* Component tokens
* -------------------------------------------------------------------------- */
elementsGutterStackedX: 'calc($gutter * 0.66)',
elementsGutterStackedY: 'calc($gutter * 0.66)',
elementsGutterX: '$gutter',
elementsGutterY: '$gutter',
}