Skip to content

Instantly share code, notes, and snippets.

@daliborgogic
Last active March 27, 2020 18:39
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 daliborgogic/b3955eab545a54f3fe345491bec82245 to your computer and use it in GitHub Desktop.
Save daliborgogic/b3955eab545a54f3fe345491bec82245 to your computer and use it in GitHub Desktop.
Dynamic Components
<template>
<form>
<Component v-for="({ type }, index) in schema" :key="index" :is="'v' + type" />
</form>
</template>
<script>
export default {
components: {
vInput: () => import('@/components/form/Input' /* webpackChunkName: "components/form/Input" */),
vTextArea: () => import('@/components/form/TextArea' /* webpackChunkName: "components/form/TextArea" */),
// Not used, not loooooaded
vCheckBox: () => import('@/components/form/TextArea' /* webpackChunkName: "components/form/CheckBox" */)
// etc
},
data: () => ({
// Predefined or created/edited in CMS for example
schema: [
{
type: 'Input',
label: 'First name'
},
{
type: 'TextArea',
label: 'Message'
}
]
})
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment