UNPKG

@maxpike/vue

Version:

Vue VariantJS: Fully configurable Vue 3 components styled with TailwindCSS

24 lines (18 loc) 475 B
import { Data } from '@variantjs/core'; import { getCurrentInstance, Ref, watch, ref, } from 'vue'; export default function useVModel<P extends Data, K extends keyof P>( props: P, key: K, ): Ref<P[K]> { const vm = getCurrentInstance(); const localValue = ref(props[key]) as Ref<P[K]>; watch(localValue, (value) => { vm?.emit(`update:${key}`, value); }); watch(() => props[key], (value) => { localValue.value = value; }); return localValue; }