欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

element 动态校验的3中方式[{}] ,‘ ‘, [ ]

程序员文章站 2022-05-03 18:04:12
...

<el-form :model="dynamicValidateForm" ref="dynamicValidateForm" label-width="100px" class="demo-dynamic">
  <el-form-item
  // 1
    prop="email"
    
    label="邮箱"
    :rules="[
      { required: true, message: '请输入邮箱地址', trigger: 'blur' },
      { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
    ]"
  >
    <el-input v-model="dynamicValidateForm.email"></el-input>
  </el-form-item>
  <el-form-item
    v-for="(domain, index) in dynamicValidateForm.domains"
    :label="'域名' + index"
    :key="domain.key"
    // 2
    :prop="'domains.' + index + '.value'"
    
    :rules="{
      required: true, message: '域名不能为空', trigger: 'blur'
    }"
  >
    <el-input v-model="domain.value"></el-input><el-button @click.prevent="removeDomain(domain)">删除</el-button>
  </el-form-item>
<el-form-item style="margin-left:0px" 
// 3
:prop="'otherUsers[' + index +']'" 

 :rules="[{ required: true, message: '此项不能为空', trigger: 'change' }]">
    <el-select v-model="from.otherUsers[index]" filterable clearable>
        <el-option v-for="item in allOnJob" :key="item.employeeId+'q'" :label="item.nameAndDepartment" :value="item.employeeId" />
    </el-select>
 </el-form-item>
data() {
      return {
        dynamicValidateForm: {
           email: '', // 1
          domains: [{ value: '' }],  // 2
          data:[  ] // 3
        }
      };
    },
相关标签: element 前端