Skip to content

Commit c0418a3

Browse files
authoredOct 11, 2024··
fix(defineModel): handle kebab-case model correctly (#12063)
close #12060
1 parent f1a4f67 commit c0418a3

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed
 

‎packages/runtime-core/__tests__/helpers/useModel.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ describe('useModel', () => {
153153

154154
const compRender = vi.fn()
155155
const Comp = defineComponent({
156-
props: ['fooBar'],
157-
emits: ['update:fooBar'],
156+
props: ['foo-bar'],
157+
emits: ['update:foo-bar'],
158158
setup(props) {
159-
foo = useModel(props, 'fooBar')
159+
foo = useModel(props, 'foo-bar')
160160
return () => {
161161
compRender()
162162
return foo.value
@@ -192,10 +192,10 @@ describe('useModel', () => {
192192

193193
const compRender = vi.fn()
194194
const Comp = defineComponent({
195-
props: ['fooBar'],
196-
emits: ['update:fooBar'],
195+
props: ['foo-bar'],
196+
emits: ['update:foo-bar'],
197197
setup(props) {
198-
foo = useModel(props, 'fooBar')
198+
foo = useModel(props, 'foo-bar')
199199
return () => {
200200
compRender()
201201
return foo.value

‎packages/runtime-core/src/helpers/useModel.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@ export function useModel(
2828
return ref() as any
2929
}
3030

31-
if (__DEV__ && !(i.propsOptions[0] as NormalizedProps)[name]) {
31+
const camelizedName = camelize(name)
32+
if (__DEV__ && !(i.propsOptions[0] as NormalizedProps)[camelizedName]) {
3233
warn(`useModel() called with prop "${name}" which is not declared.`)
3334
return ref() as any
3435
}
3536

36-
const camelizedName = camelize(name)
3737
const hyphenatedName = hyphenate(name)
38-
const modifiers = getModelModifiers(props, name)
38+
const modifiers = getModelModifiers(props, camelizedName)
3939

4040
const res = customRef((track, trigger) => {
4141
let localValue: any
4242
let prevSetValue: any = EMPTY_OBJ
4343
let prevEmittedValue: any
4444

4545
watchSyncEffect(() => {
46-
const propValue = props[name]
46+
const propValue = props[camelizedName]
4747
if (hasChanged(localValue, propValue)) {
4848
localValue = propValue
4949
trigger()

0 commit comments

Comments
 (0)
Please sign in to comment.