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

疑似 Form 组件的 Bug #139

Closed
ydq opened this issue Dec 10, 2024 · 3 comments
Closed

疑似 Form 组件的 Bug #139

ydq opened this issue Dec 10, 2024 · 3 comments

Comments

@ydq
Copy link

ydq commented Dec 10, 2024

按照官网的文档,当不使用校验的时候,输入框的 clear 事件没能触发 form 的 change 事件,导致获取的值是旧的过时的值

bug

最小复现:

<script setup>
import { ref } from 'vue';

const form = ref({})
const formRef = ref()
const options = [
    {
        field: 'field1',
        label: 'field1',
        as: 'input',
        props: { clearable: true } // ← 允许清空,且不做校验
    },
    {
        field: 'field2',
        label: 'field2',
        as: 'input',
        props: { clearable: true } // ← 允许清空,且不做校验
    },
    {
        as: 'button',
        props: {
            text: '提交',
            async request(){
                // 文本框的 clear 事件没能触发 form 的 change 函数,导致清空之后 获取的还是上一次的值
                console.log(JSON.stringify(form.value))
            }
        }
    },
]

</script>
<template>
    <lew-flex width="500"
              x="start"
              y="start"
              :gap="50">
        <lew-form ref="formRef"
                  :options="options"
                  @change="e => { form = e }" />
    </lew-flex>
</template>
@lewkamtao
Copy link
Owner

方法使用错误了,不应该用change来获取form的值,可以试试formRef.value.getForm(),这个方法是获取最新的表单绑定值。

@lewkamtao
Copy link
Owner

image
这个set和get的两个方法 是这个form的核心。

@ydq
Copy link
Author

ydq commented Dec 12, 2024

方法使用错误了,不应该用change来获取form的值,可以试试formRef.value.getForm(),这个方法是获取最新的表单绑定值。

非常感谢,上面是跟着官网的示例来写的,当时没想那么多

@ydq ydq closed this as completed Dec 12, 2024
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