liAnran

博客园 首页 新随笔 联系 订阅 管理

html:

<el-form-item label="所属分类" prop="speconeclass">
            <el-select v-model="topform.speconeclass" size="mini" placeholder="请选择一级分类">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
            <el-select
              v-model="topform.spectwoclass"
              size="mini"
              placeholder="请选择二级分类"
              ref="spectwoclass"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>

rules:

speconeclass: [
          { required: true, validator: this.checkFrequency, trigger: "change" }
        ]

methods:

//同时验证两个select框
    checkFrequency(rule, value, callback) {
      let spectwoclass = this.$refs.spectwoclass.value;
      if (value && spectwoclass) {
        callback();
      } else {
        callback(new Error("请选择一级分类和二级分类"));
      }
    },

 

posted on 2019-05-30 18:03  liAnran  阅读(637)  评论(0编辑  收藏  举报