Skip to content

Instantly share code, notes, and snippets.

@crutchcorn
Created November 2, 2021 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crutchcorn/951c192429ef07d19265edbe5930e09b to your computer and use it in GitHub Desktop.
Save crutchcorn/951c192429ef07d19265edbe5930e09b to your computer and use it in GitHub Desktop.
<template>
<div>
<div
v-for="field of fields"
:key="field.id"
>
<input
v-if="field.value === 'input'"
:value="field.value"
:aria-label="field.label"
@change="field.onChange"
>
<select
v-if="field.value === 'select'"
:value="field.value"
:aria-label="field.label"
@change="field.onChange"
>
<option
v-for="option of field.options"
:key="option"
>
{{ option }}
</option>
</select>
</div>
</div>
</template>
<script>
export default {
data() {
return {
fields: [
{
id: '1',
label: 'Test',
value: 'Preset val',
// Append props
onChange(e) {
this.data.fields[0] = e.target.value;
},
type: 'input'
},
{
id: '2',
label: 'Second',
value: 'Second val',
// Append props
onChange(e) {
this.data.fields[1] = e.target.value;
},
type: 'input'
},
{
id: '3',
label: 'Second',
value: '2',
options: [
'2',
'3'
],
// Append props
onChange(e) {
this.data.fields[1] = e.target.value;
},
type: 'select'
}
]
};
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment