From c0edc361cb2e03868b2f5a8e863f1f9147b9a6e0 Mon Sep 17 00:00:00 2001 From: pengYYY Date: Fri, 13 May 2022 10:05:18 +0800 Subject: [PATCH] chore: pref code --- src/hooks/useDefaultValue.ts | 11 ++++------- src/hooks/useVModel.ts | 18 ++++++------------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/hooks/useDefaultValue.ts b/src/hooks/useDefaultValue.ts index 01e87f2430..c7e19f9884 100644 --- a/src/hooks/useDefaultValue.ts +++ b/src/hooks/useDefaultValue.ts @@ -17,13 +17,10 @@ export default function useDefaultValue( internalValue.value = value.value; } - // 监听value与modelValue的变化 - watch( - () => value.value, - (newVal) => { - internalValue.value = newVal; - }, - ); + // 监听value变化 + watch(value, (newVal) => { + internalValue.value = newVal; + }); // 非受控模式 return [ diff --git a/src/hooks/useVModel.ts b/src/hooks/useVModel.ts index 2f7bb2a0d0..86d6139151 100644 --- a/src/hooks/useVModel.ts +++ b/src/hooks/useVModel.ts @@ -25,18 +25,12 @@ export default function useVModel( } // 监听value与modelValue的变化 - watch( - () => value.value, - (newVal) => { - internalValue.value = newVal; - }, - ); - watch( - () => modelValue.value, - (newVal) => { - internalValue.value = newVal; - }, - ); + watch(value, (newVal) => { + internalValue.value = newVal; + }); + watch(modelValue, (newVal) => { + internalValue.value = newVal; + }); return [ internalValue,