Skip to content

Commit

Permalink
Update vModel.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 authored Nov 9, 2023
1 parent e2672da commit 2837525
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions packages/runtime-dom/src/directives/vModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,25 @@ export const vModelText: ModelDirective<
el[assignKey] = getModelAssigner(vnode)
// avoid clearing unresolved text. #2302
if ((el as any).composing) return

const elValue =
number || el.type === 'number' ? looseToNumber(el.value) : el.value
const newValue = value == null ? '' : value

if (elValue === newValue) {
return
}

if (document.activeElement === el && el.type !== 'range') {
if (lazy) {
return
}
if (trim && el.value.trim() === value) {
if (trim && el.value.trim() === newValue) {
return
}
if (
(number || el.type === 'number') &&
looseToNumber(el.value) === value
) {
return
}
}
const newValue = value == null ? '' : value
// #7003 v-model can update correctly when the element is an input of type number
const elValue =
el.type === 'number' && vnode.type === 'input'
? Number(el.value)
: el.value
if (elValue !== newValue) {
el.value = newValue
}

el.value = newValue
}
}

Expand Down

0 comments on commit 2837525

Please sign in to comment.