fix(input): 修复 input 内 preValue 计算错误问题(#3347) #3427
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.
Types of changes
Background and context
#3347
虽然 issue 中提到的是 inputNumber 组件,但实际上这个错误发生在 input 组件中。
可以查看 demo:https://codesandbox.io/p/sandbox/floral-framework-jjvymj?file=%2Fsrc%2FApp.vue%3A23%2C1
复现流程:默认值是 123,输入一个 4,按回车键触发 change 事件,现在 input 显示 1234,也可以看到控制台输出,等三秒定时器将输入内容设置为 789,这时候再修改为 1234,按回车,不会触发 change 事件。(注意这个过程不要让输入框失去焦点)
Solution
原逻辑是在 input 组件聚焦及触发 change 事件时更新 preValue,现使用 watch 第二个参数 oldValue 进行更新。
How is the change tested?
Changelog
Checklist:
npm run test
)feature
branch and othersshould be submitted to
main
branch)Other information