element-ui 在使用時間組件時指定待選項。

在一些時候我們需要限定某些日期是否可選。
這裏限定一下可選月份兒爲 3 / 6 / 9 / 12 其它都爲不可選狀態

<template>
  <div class="block">
    <span class="demonstration">默認</span>
    <el-date-picker
      v-model="value1"
      type="month"
      value-format="yyyyMM"
      :picker-options="pickerTime"  // 重點 1
      placeholder="選擇日期">
    </el-date-picker>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        pickerTime: {  // 重點 2
                    disabledDate: function(time) {
                        var curDate = (new Date()).getMonth();
                        return ((
                            time.getMonth() == 0 ||
                            time.getMonth() == 1 ||
                            time.getMonth() == 3 ||
                            time.getMonth() == 4 ||
                            time.getMonth() == 6 ||
                            time.getMonth() == 7 ||
                            time.getMonth() == 9 ||
                            time.getMonth() == 10
                        ))
                    }
                },
        value1: '',
        value2: '',
      };
    }
  };
</script>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章