Skip to content

WHY v-model.lazy won't update the focus input dom/ 双向绑定的input元素,回车触发watch回调中修改的值不会更新到input中 #8238

Discussion options

You must be logged in to vote

我在官方源码里面已经找到原因了,但是对于官方尤大这样的选择仍然不太清楚,可能是基于某些需求下的考量:
当某个input用lazy绑定的响应式在变化时,用户如果刚好也在编辑这个输入,那么变化的数据为了不影响用户的编辑,不会主动更新这个值到输入框;
好处是上面的这种情况,以用户输入体验为主。坏处就是当开发者想主动更新时就会发生问题。
示例代码仍然在https://codepen.io/xflyyxfl-the-typescripter/pen/poxpwKK?editors=1010
/////
I have found the reason in the official source code, but it is still not clear for the official/You such choice, may be based on some needs under consideration:

When an input is changing with lazy-bound responses, if the user happens to be editing the input, the changed data will not update the value to the input box so as not to affect the user's editing

The benefit is that in the case above, the user input experience is the primary one. The d…

Replies: 8 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by xflyyxfl
Comment options

You must be logged in to vote
2 replies
@Justineo
Comment options

Justineo May 6, 2023
Collaborator

@xflyyxfl
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #8235 on May 05, 2023 17:16.