diff --git a/packages/runtime-core/__tests__/helpers/useModel.spec.ts b/packages/runtime-core/__tests__/helpers/useModel.spec.ts index 3c724b0ba00..8d31848e1bc 100644 --- a/packages/runtime-core/__tests__/helpers/useModel.spec.ts +++ b/packages/runtime-core/__tests__/helpers/useModel.spec.ts @@ -153,10 +153,10 @@ describe('useModel', () => { const compRender = vi.fn() const Comp = defineComponent({ - props: ['fooBar'], - emits: ['update:fooBar'], + props: ['foo-bar'], + emits: ['update:foo-bar'], setup(props) { - foo = useModel(props, 'fooBar') + foo = useModel(props, 'foo-bar') return () => { compRender() return foo.value @@ -192,10 +192,10 @@ describe('useModel', () => { const compRender = vi.fn() const Comp = defineComponent({ - props: ['fooBar'], - emits: ['update:fooBar'], + props: ['foo-bar'], + emits: ['update:foo-bar'], setup(props) { - foo = useModel(props, 'fooBar') + foo = useModel(props, 'foo-bar') return () => { compRender() return foo.value diff --git a/packages/runtime-core/src/helpers/useModel.ts b/packages/runtime-core/src/helpers/useModel.ts index 37fd1d719b0..c40938ead3c 100644 --- a/packages/runtime-core/src/helpers/useModel.ts +++ b/packages/runtime-core/src/helpers/useModel.ts @@ -28,14 +28,14 @@ export function useModel( return ref() as any } - if (__DEV__ && !(i.propsOptions[0] as NormalizedProps)[name]) { + const camelizedName = camelize(name) + if (__DEV__ && !(i.propsOptions[0] as NormalizedProps)[camelizedName]) { warn(`useModel() called with prop "${name}" which is not declared.`) return ref() as any } - const camelizedName = camelize(name) const hyphenatedName = hyphenate(name) - const modifiers = getModelModifiers(props, name) + const modifiers = getModelModifiers(props, camelizedName) const res = customRef((track, trigger) => { let localValue: any @@ -43,7 +43,7 @@ export function useModel( let prevEmittedValue: any watchSyncEffect(() => { - const propValue = props[name] + const propValue = props[camelizedName] if (hasChanged(localValue, propValue)) { localValue = propValue trigger()