Skip to content
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

二次开发导致表单验证功能异常 #7159

Closed
1 task done
zzzgit opened this issue Dec 5, 2023 · 2 comments
Closed
1 task done

二次开发导致表单验证功能异常 #7159

zzzgit opened this issue Dec 5, 2023 · 2 comments

Comments

@zzzgit
Copy link

zzzgit commented Dec 5, 2023

  • I have searched the issues of this repository and believe that this is not a duplicate.

image

Version

最新

Environment

Node.js 22, Chrome 最新

Reproduction link

Edit on CodeSandbox

Steps to reproduce

  1. 对a-input进行封装,看b-input
  2. 在demo.vue的表单中,使用 a-input和b-input
  3. a-input校验功能行为正常,b-input的校验功能行为异常
    1. 在id输入框,输入第一个字母,出现校验失败的信息(因为异步校验取到的data.value为空字符串)
    2. 在id输入框,输入第二个字母,校验通过(因为异步校验取到的data.value为上一个字母)

What is expected?

二次开发不影响校验功能

What is actually happening?

校验功能异常

demo中的数据流:
demo.vue中数据formState.userid绑定了b-input的value属性,而b-input中的inner_value绑定了a-input的value属性。
如果在输入框中输入,先是a-input产生update:value事件,然后才是b-input中产生update:value事件,此时已经来不及了,因为校验过程已经开始,校验函数取到的数据旧数据。

@bsuooo
Copy link
Contributor

bsuooo commented Dec 5, 2023

我猜测是因为校验事件触发的时候 你的监听赋值还没开始
这样封装好麻烦, 为什么不试试computed 或者customRef
比如
image

@zzzgit
Copy link
Author

zzzgit commented Dec 5, 2023

解決了。
演示
演示2,有瑕疵

@zzzgit zzzgit closed this as completed Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants