小编ruf*_*ulk的帖子

Vee validate v3 ValidationObserver 无法与使用 v-for 添加的动态验证提供程序一起使用

我使用 Vee Validate v3 来验证使用 V-FOR 生成的动态输入,V-FOR 会根据用户操作添加或删除输入元素。

我的问题是只有最后一个输入得到验证,其他输入没有得到验证。在文档中,他们在使用 V-IF 和 V-FOR 文档链接时提到了这个问题

他们告诉我们使用 VueJS keep-alive组件。但不能与 V-FOR 一起使用。

<validation-observer ref="observer" v-slot="{ handleSubmit }">
<form method="POST" action="{{ route('app.store') }}" @submit.prevent="handleSubmit(onSubmit)" class="form" enctype="multipart/form-data">
    <table class="table">
        <thead>
            <tr>
                <th>SI No</th>
                <th>input 1</th>
            </tr>
        </thead>
        <tbody>
            <tr v-for="(item, index) in items" :key="item.id">
                <td>@{{ index + 1 }}</td>
                <td>
                    <keep-alive>
                        <validation-provider rules="required" v-slot="{ errors }" name="attribute">
                            <div class="form-group">
                                <input :name="'attribute' + item.id" class="form-control" v-model="item.attribute">
                                <span class="error" role="alert">

                                    @{{ errors[0] }}

                                </span>
                            </div>
                        </validation-provider>
                    </keep-alive> …
Run Code Online (Sandbox Code Playgroud)

javascript laravel laravel-blade vuejs2 vee-validate

3
推荐指数
1
解决办法
7498
查看次数