refactor: use vue built-in defineModel

This commit is contained in:
Piotr Wasak 2024-11-16 13:58:11 +01:00
parent ac69980ac9
commit e9082b2e3d
2 changed files with 4 additions and 20 deletions

View File

@ -1,22 +1,14 @@
<script setup lang="ts">
import type { HTMLAttributes } from 'vue'
import { cn } from '@/lib/utils'
import { useVModel } from '@vueuse/core'
const props = defineProps<{
class?: HTMLAttributes['class']
defaultValue?: string | number
modelValue?: string | number
}>()
const emits = defineEmits<{
(e: 'update:modelValue', payload: string | number): void
}>()
const modelValue = useVModel(props, 'modelValue', emits, {
passive: true,
defaultValue: props.defaultValue,
})
const modelValue = defineModel<string | number>({ default: '' })
modelValue.value = props.defaultValue
</script>
<template>

View File

@ -1,22 +1,14 @@
<script setup lang="ts">
import type { HTMLAttributes } from 'vue'
import { cn } from '@/lib/utils'
import { useVModel } from '@vueuse/core'
const props = defineProps<{
class?: HTMLAttributes['class']
defaultValue?: string | number
modelValue?: string | number
}>()
const emits = defineEmits<{
(e: 'update:modelValue', payload: string | number): void
}>()
const modelValue = useVModel(props, 'modelValue', emits, {
passive: true,
defaultValue: props.defaultValue,
})
const modelValue = defineModel<string | number>({ default: '' })
modelValue.value = props.defaultValue
</script>
<template>