Skip to content

Commit

Permalink
fix(defineModel): handle kebab-case model correctly (vuejs#12063)
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX authored Oct 11, 2024
1 parent f1a4f67 commit c0418a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions packages/runtime-core/__tests__/helpers/useModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions packages/runtime-core/src/helpers/useModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 28,22 @@ 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
let prevSetValue: any = EMPTY_OBJ
let prevEmittedValue: any

watchSyncEffect(() => {
const propValue = props[name]
const propValue = props[camelizedName]
if (hasChanged(localValue, propValue)) {
localValue = propValue
trigger()
Expand Down

0 comments on commit c0418a3

Please sign in to comment.