Vee-validate的USEFieldArray仅与解构一起使用

发布于 2025-01-27 13:58:18 字数 1015 浏览 0 评论 0原文

对所有人来说,美好的一天,

有人可以向我解释为什么Vee-validates useFieldArray才能在我解构时正确工作吗?

模板:

        // For the working example I use "fields" instead of fieldArray.fields.
        // Nothing more, nothing less
        <div v-for="(field, idx) in fieldArray.fields" 
             class="d-flex justify-content-between align-items-center">
            <div>
                <FormControl :id="`${props.type}[${idx}].name`"></FormControl>
            </div>
            <div>
                <Checkbox :id="`${props.type}[${idx}].value`"></Checkbox>
            </div>
        </div>

工作:

const form = useForm({initialValues: {[props.type]: getInitialFormValues()}});
const {fields, push} = useFieldArray(props.type)

不工作:

const form = useForm({initialValues: {[props.type]: getInitialFormValues()}});
const fieldArray = useFieldArray(props.type)

谢谢您!

Good day to all,

can someone explain me why vee-validates useFieldArray only works correctly when I deconstruct it?

Template:

        // For the working example I use "fields" instead of fieldArray.fields.
        // Nothing more, nothing less
        <div v-for="(field, idx) in fieldArray.fields" 
             class="d-flex justify-content-between align-items-center">
            <div>
                <FormControl :id="`${props.type}[${idx}].name`"></FormControl>
            </div>
            <div>
                <Checkbox :id="`${props.type}[${idx}].value`"></Checkbox>
            </div>
        </div>

Working:

const form = useForm({initialValues: {[props.type]: getInitialFormValues()}});
const {fields, push} = useFieldArray(props.type)

Not working:

const form = useForm({initialValues: {[props.type]: getInitialFormValues()}});
const fieldArray = useFieldArray(props.type)

Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十雾 2025-02-03 13:58:18

我想,如果您不解构对象,则需要包装值()。

尝试此

const form = useForm({initialValues: {[props.type]: getInitialFormValues()}});

更改为

import { ref } from 'vue';

const form = ref(useForm({initialValues: {[props.type]: getInitialFormValues()}}));

(对于Vue&gt; = 3)

I guess, you need wrap values to ref(), if you do not deconstruct object.

Try this

const form = useForm({initialValues: {[props.type]: getInitialFormValues()}});

change to

import { ref } from 'vue';

const form = ref(useForm({initialValues: {[props.type]: getInitialFormValues()}}));

(for vue >= 3)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文