el-cascader 多选时的 校验 回显


<el-form-item
  label="部门"
  prop="departments"
>
  <el-cascader
    v-model="form.departments"
    :options="departOptions"
    :show-all-levels="false"
    :props="{
      label: 'name',
      value: 'id',
      children: 'child',
      multiple: true,
      emitPath: false
    }"
    clearable
    size="mini"
    style="width:100%"
  >
  </el-cascader>
</el-form-item>
departments: [{ type: 'array', required: true, validator: checkDepartments}]
const checkDepartments = (rule, value, cb) => {
  if (this.form.departments.length === 0) {
     cb(new Error('请选择部门'));
  } else {
     cb();
  }
}

//回显
this.form.departments = res.data.departments.map(item => item.id)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM