elementui 动态表单问题

1. 问题

最近碰到一个问题,就是在 vue.js 项目中搭配 elementui 组件库中的 el-form 动态表单问题,踩了一点坑,在此记录

            <el-row
              v-for="(item, index) in propertyGroup"
              :key="index"
            >
              <el-row
                class="basic-info-title"
                type="flex"
                justify="start"
                align="middle"
              >
                <span class="green-line"></span>
                <span>{{ item.groupName }}</span>
              </el-row>

              <el-row
                type="flex"
                justify="start"
                align="middle"
                style="margin-bottom: 12px; flex-wrap: wrap;"
              >
                <el-form-item
                  v-for="(list, j) in item.groupProperty"
                  :label="list.name"
                  :key="j"
                  :prop="
                    'propertyGroup.' + index + '.groupProperty.' + j + '.value'
                  "
                  :rules="{
                    required: list.unique,
                    message: `${list.name}不能为空`,
                    trigger: 'blur'
                  }"
                >
                  <el-input
                    v-model="list.value"
                    v-if="list.type === 'text'"
                    class="common-input input-distance"
                  ></el-input>
                </el-form-item>
              </el-row>
            </el-row>

重点在第二层循环 prop 绑定的问题, 'propertyGroup.' + index + '.groupProperty.' + j + '.value',是第一层和第二层的数组和 index 都要加上,要不然验证加不上。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容