A Vue 3 version of vue-form-generator
, a schema-based form generator.
- Install plugin in your Vue app, this will make all necessary components globally available in your app.
// ...
import VueFormGenerator from 'vue3-form-generator'
app.use(VueFormGenerator)
// ...
- Define a schema inside your Vue component
<template>
<vue-form-generator :schema="form.schema" :model="form.model"/>
</template>
<script setup>
import { ref } from 'vue'
const form = ref({
model: {
name: '',
terms: false,
},
schema: {
fields: [
{
name: 'name',
label: 'Name',
type: 'input',
inputType: 'text',
model: 'name',
placeholder: "Write name...",
readonly: false,
required: true,
},
{
name: 'terms',
label: 'Accept terms and conditions',
type: 'input',
inputType: 'checkbox',
model: 'terms',
}
]
}
})
</script>
<template>
<vue-form-generator :schema="form.schema" :model="form.model"/>
</template>
<script>
export default {
data () {
return {
form: {
model: {
name: '',
},
schema: {
fields: [
{
name: 'name',
label: 'Name',
type: 'input',
inputType: 'text',
model: 'name',
placeholder: "Write name...",
readonly: false,
required: true,
}
]
}
}
}
}
}
</script>