Last active
March 29, 2019 19:51
-
-
Save swthate/504215523c73cdb034e3ab00000755fc to your computer and use it in GitHub Desktop.
Vue component with array of objects as a prop
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
<town-form :fields="[ { component:'TownFieldTitle', name:'title' } ]"></town-form> |
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> | |
<!-- Dynamic list of fields from template --> | |
<Component v-for="(field, index) in fields" :is="field.component" :key="index" v-model="fields[field.name]" /> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: 'TownForm', | |
props: { | |
fields: { | |
type: Array, | |
default: function () { | |
return [ { component: 'TownFieldTitle', name: 'title' } ] | |
} | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Jake Dohm is the genius behind this.
Todo:
slots
?