Skip to content

Instantly share code, notes, and snippets.

@GavinRay97
Last active July 13, 2020 15:09
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 GavinRay97/4472e3f48c4fb23a735ddaf1fee65e0b to your computer and use it in GitHub Desktop.
Save GavinRay97/4472e3f48c4fb23a735ddaf1fee65e0b to your computer and use it in GitHub Desktop.
v-switch component
<!-- 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