<template>
    <el-input-number v-model="warningValue" :min="0" :max="100" class="warn-innput w-46px" :controls="false" @blur="inputBlur" />
</template>

<script setup>
import { ref, watch } from 'vue'
import { isNullES } from 'js-fast-way'

defineOptions({
    name: 'HcInputNumber',
})

//双向绑定
const modelValue = defineModel('modelValue', {
    type: [String, Number],
    default: '',
})

//监听数据改变
const warningValue = ref('')
watch(() => modelValue.value, (val) => {
    warningValue.value = isNullES(val) ? null : Number(val)
}, { deep: true, immediate:true })

//输入内容改变
const inputBlur = () => {
    modelValue.value = warningValue.value
}
</script>
