-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(vModel): fix v-model
being reset in updated
#8639
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
eabf0b9
fix(vModel): fix the issue where `checked` gets reset during an update
Alfred-Skyblue 1e75eae
Merge branch 'main' into fix-vModel-checkbox
Alfred-Skyblue 7bbc8f3
Merge branch 'main' into fix-vModel-checkbox
Alfred-Skyblue 6860053
chore: fix select update reset
Alfred-Skyblue 3075047
Merge branch 'main' into fix-vModel-checkbox
Alfred-Skyblue 43aa560
Merge branch 'main' into fix-vModel-checkbox
Alfred-Skyblue 96914bf
Merge branch 'main' into fix-vModel-checkbox
Alfred-Skyblue e468fea
Merge branch 'main' into fix-vModel-checkbox
Alfred-Skyblue 65f0d62
Merge branch 'main' into fix-vModel-checkbox
Alfred-Skyblue 16319fc
Merge branch 'main' into fix-vModel-checkbox
Alfred-Skyblue 3880db7
Merge branch 'main' into fix-vModel-checkbox
Alfred-Skyblue 3b9227b
Merge branch 'main' into fix-vModel-checkbox
Alfred-Skyblue 4029e29
Merge branch 'main' into fix-vModel-checkbox
Alfred-Skyblue db2a2bc
Merge branch 'main' into fix-vModel-checkbox
Alfred-Skyblue ba98c40
Merge branch 'main' into fix-vModel-checkbox
Alfred-Skyblue 8a85377
fix: number not passed
Alfred-Skyblue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,14 +155,16 @@ function setChecked( | |
{ value, oldValue }: DirectiveBinding, | ||
vnode: VNode, | ||
) { | ||
// store the v-model value on the element so it can be accessed by the | ||
// change listener. | ||
// #8638 | ||
if (value === oldValue) | ||
return // store the v-model value on the element so it can be accessed by the | ||
// change listener. | ||
Comment on lines
+160
to
+161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prettier has moved this comment, so it's now in the wrong place. I think you'll need to add braces around the |
||
;(el as any)._modelValue = value | ||
if (isArray(value)) { | ||
el.checked = looseIndexOf(value, vnode.props!.value) > -1 | ||
} else if (isSet(value)) { | ||
el.checked = value.has(vnode.props!.value) | ||
} else if (value !== oldValue) { | ||
} else { | ||
el.checked = looseEqual(value, getCheckboxValue(el, true)) | ||
} | ||
} | ||
|
@@ -216,8 +218,9 @@ export const vModelSelect: ModelDirective<HTMLSelectElement> = { | |
beforeUpdate(el, _binding, vnode) { | ||
el[assignKey] = getModelAssigner(vnode) | ||
}, | ||
updated(el, { value, modifiers: { number } }) { | ||
if (!el._assigning) { | ||
updated(el, { value, oldValue, modifiers: { number } }) { | ||
// #8579 | ||
if (!el._assigning && value !== oldValue) { | ||
setSelected(el, value, number) | ||
} | ||
}, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning early like this won't work if the
value
is an Array or Set that's been modified. e.g.:Running this same example against
main
works as expected:main