Created
November 2, 2021 18:38
-
-
Save crutchcorn/951c192429ef07d19265edbe5930e09b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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