基于elementui的区间输入(最小值-最大值)

使用:

                  placeholderMin="最小值"
                  placeholderMax="最大值"
                  clearable
                  v-model="contractCost">
                </ec-input-range>

实现:

  <div class="ec-input-range">
    <el-input
      v-model="val.min"
      @input="val.min=val.min.replace(/[^\d]/g,' ')"
      @blur="handleVal"
      :placeholder="placeholderMin"
    ></el-input>
    <div class="ec-input-range-divider"></div>
    <el-input
      v-model="val.max"
      @input="val.max=val.max.replace(/[^\d]/g,' ')"
      @blur="handleVal"
      :placeholder="placeholderMax"
    ></el-input>
  </div>
</template>
<script>
export default {
  name: "EcInputRange",
  data() {
    return {
      val: {
        min: '',
        max: '',
      },
    };
  },
  props: {
    placeholderMin: {
      type: String,
      default: "请输入",
    },
    placeholderMax: {
      type: String,
      default: "请输入",
    },
  },
  model: {
    prop: "val",
    event: "input",
  },
  methods: {
    handleVal() {
      const _this = this;
      if (_this.val.min == "" || _this.val.min == undefined || _this.val.min == null ||
          _this.val.max == "" || _this.val.max == undefined || _this.val.max == null) {
            _this.$emit("input", _this.val);
      } else {
        if (Number(_this.val.min) >= Number(_this.val.max)) {
          _this.$message({
            type: 'warning',
            message: '区间最小值需要小于最大值!',
            onClose: function () {
              _this.val.min = '';
              _this.val.max = '';
            }
          });
          return
        }
        _this.$emit("input", _this.val);
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.ec-input-range-divider {
  display: inline-block;
    width: 7px;
    height: 1px;
    background: #c0c4cc;
    margin-bottom: 4px;
}
</style>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容