乐趣区

关于vue.js:elformitem校验多个字段

<el-form-item label=” 考勤周期:” prop=”cycleEnd”>

<el-select @change="cycleChange" v-model="formmodel.cycle">
    <el-option
    v-for="item in cycleOption"
    :key="item.id"
    :label="item.label"
    :value="item.id"
    >
    </el-option>
</el-select>
<el-select v-model="formmodel.cycleStart">
    <el-option
    v-for="item in cycleDateOption"
    :key="item.id"
    :label="item.label"
    :value="item.id"
    >
    </el-option>
</el-select>
<el-select v-model="formmodel.cycleEnd">
    <el-option
    v-for="item in cycleDateOption"
    :key="item.id"
    :label="item.label"
    :value="item.id"
    >
    </el-option>
</el-select>

</el-form-item>

data() {

return {
  visible: false,
  formmodel: {cycle:'1'},
  formRules: {date: [{ required: true, message: "请抉择考勤月份"}],
    cycleEnd: [{required: true, validator:(rules,value,callback)=>{let {cycleStart} = this.formmodel
      if (!value||!cycleStart) {return callback(new Error("请抉择考勤周期"))
      }
      return callback()} }],
  },
  formRules2: {date: [{ required: true, message: "请抉择考勤月份"}]
  }
};

},

退出移动版