Last active
July 13, 2020 15:09
-
-
Save GavinRay97/4472e3f48c4fb23a735ddaf1fee65e0b to your computer and use it in GitHub Desktop.
v-switch component
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
<!-- File: `v-switch.vue` --> | |
<script> | |
export default { | |
functional: true, | |
props: { | |
value: { type: [String, Number], required: true } | |
}, | |
render(h, { data, props, scopedSlots }) { | |
const { value } = props | |
const slotFn = value in scopedSlots ? scopedSlots[value] : scopedSlots.default | |
return slotFn ? slotFn(data.attrs) : null | |
} | |
} | |
</script> | |
<!-- Usage as follows: --> | |
<template> | |
<div> | |
<v-switch :value="headingType"> | |
<template #big> | |
<h1>Headline</h1> | |
</template> | |
<template #small> | |
<h2>Headline</h2> | |
</template> | |
<template #smaller> | |
<h3>Headline</h3> | |
</template> | |
<!-- Optional: `<template #default></template>` --> | |
</v-switch> | |
</div> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment