This commit is contained in:
lijianyou
2025-09-30 15:00:32 +08:00
parent 1b262f06b8
commit b4e759cf69
202 changed files with 22035 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
import { watch, computed, ref } from 'vue';
function useModelValue<T>(value: () => T | undefined, onChange: (val?: T) => void, defaultValue?: T) {
const _value = ref<T>();
_value.value = value() ?? defaultValue;
const sValue = computed({
get() {
return value() ?? _value.value;
},
set(val: T | undefined) {
_value.value = val;
onChange(val);
},
});
watch(value, () => {
_value.value = value();
});
return { value: sValue };
}
export default useModelValue;