Skip to content

Instantly share code, notes, and snippets.

@lordzouga
Created October 2, 2023 18:33
Show Gist options
  • Save lordzouga/866c515f27e9b0eb3bc8d47842afd44c to your computer and use it in GitHub Desktop.
Save lordzouga/866c515f27e9b0eb3bc8d47842afd44c to your computer and use it in GitHub Desktop.
A Basic template for extending Nuxt UI components
<script lang="js">
import { USlideover } from '#components';
/* Extend USlideover so as to emit signal when the slider is opened */
export default defineComponent({
emits: ['open', 'update:modelValue'],
extends: USlideover,
props: ['modelValue'],
setup(props, { emit, slots }) {
const { modelValue } = toRefs(props);
// watch the v-model value
watch(modelValue, (_new, _) => {
// only emit an event when this value is true
if (_new) nextTick(() => emit('open'));
});
/* render the component with original props */
return () => h(USlideover, {
...props,
// map the v-model signal of this component to the v-model signal of the parent component
'onUpdate:modelValue': (value) => emit('update:modelValue', value)
}, {
// map the slots. Only use when the component has slots implemented.
default: () => slots.default()
});
}
});
</script>
@davestewart
Copy link

Thanks for this. Have managed to extend it into something more generalised, so appreciate the ideas!

@lordzouga
Copy link
Author

@davestewart you are welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment