diff --git a/src/shared/useVModel/index.ts b/src/shared/useVModel/index.ts index b21c7fc2d..ab3a701d9 100644 --- a/src/shared/useVModel/index.ts +++ b/src/shared/useVModel/index.ts @@ -1,5 +1,4 @@ import { ref, Ref, getCurrentInstance, ComponentInternalInstance } from 'vue'; -import kebabCase from 'lodash/kebabCase'; export type ChangeHandler = (value: T, ...args: any[]) => void; @@ -11,20 +10,12 @@ export function useVModel( propName = 'value', // emit 和 eventName 用于支持 v-model 和 xxx.sync 语法糖 ): [Ref, ChangeHandler] { - const { emit, vnode } = getCurrentInstance() as ComponentInternalInstance; + const { emit } = getCurrentInstance() as ComponentInternalInstance; const internalValue = ref() as Ref; internalValue.value = defaultValue; - const vProps = vnode.props || {}; - const isVM = - Object.prototype.hasOwnProperty.call(vProps, 'modelValue') || - Object.prototype.hasOwnProperty.call(vProps, 'model-value'); - const isVMP = - Object.prototype.hasOwnProperty.call(vProps, propName) || - Object.prototype.hasOwnProperty.call(vProps, kebabCase(propName)); - // 受控模式 v-model:propName - if (isVMP) { + if (typeof value.value !== 'undefined') { return [ value, (newValue, ...args) => { @@ -35,7 +26,7 @@ export function useVModel( } // 受控模式:modelValue v-model - if (isVM) { + if (typeof modelValue.value !== 'undefined') { return [ modelValue, (newValue, ...args) => {