当前位置:   article > 正文

el-form循环生成el-form-item校验失败原因_el-table-column 嵌套 el-form-item 校验 不生效

el-table-column 嵌套 el-form-item 校验 不生效

划重点:
:prop="‘specificationsCopy.’+scope.$index+’.name’"
:rules=“rules.name”

如果:rules=“rules.name” 换成required就会报错xxx is required
在这里插入图片描述

<el-form-item label="商品规格:" required>
            <div class="table">
              <el-table :data="ruleForm.specificationsCopy" row-key="skuId" border style="width: 100%" :header-cell-style="{ background: '#F7F7F7' }">
                <el-table-column prop="date" label="商品规格" header-align="center">
                  <template slot="header">
                    <span>商品规格</span>
                  </template>
                  <template slot-scope="scope">
                    <el-form-item :prop="'specificationsCopy.'+scope.$index+'.name'" :rules="rules.name">
                      <el-input v-model="scope.row.name" :disabled="pageInfo.type==='check'" placeholder="请输入商品规格" />
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column prop="name" label="规格值" header-align="center">
                  <template slot="header">
                    <span>规格值</span>
                  </template>
                  <template slot-scope="scope">
                    <el-form-item :prop="'specificationsCopy.'+ scope.$index +'.value'" :rules="rules.value">
                      <el-input v-model="scope.row.value" :disabled="pageInfo.type==='check'" placeholder="请输入规格值" />
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column prop="address" label="操作" header-align="center" width="140" align="center">
                  <template slot-scope="scope">
                    <el-button type="text" class="danger" :disabled="pageInfo.type==='check'||ruleForm.specificationsCopy.length===1" @click="delSku(scope.$index)">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <el-button style="margin-top:12px" type="primary" :disabled="pageInfo.type==='check'" @click="addSku">添加商品规格</el-button>
            </div>
          </el-form-item>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

data定义格式

  ruleForm: {
        specificationsCopy: {
          mainTitle: "",
          name: "",
          value: "",
        }
      },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

定义规则

      rules: {
        mainTitle: [
          { required: true, message: '请输入主标题', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '请输入商品规格', trigger: 'blur' }
        ],
        value: [
          { required: true, message: '请输入规格值', trigger: 'blur' }
        ],
      },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/112794
推荐阅读
相关标签