美文网首页
Element-ui时间选择器禁止选择当月之后的月份

Element-ui时间选择器禁止选择当月之后的月份

作者: zZ_d205 | 来源:发表于2022-02-14 13:46 被阅读0次
我们常常用到elementUI中的el-date-picker组件,在组件中有个picker-options属性可对时间的选择进行限制。
<el-date-picker
     v-model="fixValue"
       type="month"
       class="fl"
       value-format="yyyy-MM"
       clearable
       size="mini"
       placeholder="选择日期"
       :picker-options="pickerOptions"
     >
 </el-date-picker>


data(){
   return{
      pickerOptions: {
        disabledDate(time) {
          const FullYear = time.getFullYear()
          let myDate = new Date();
          // const Month = time.getMonth() + 1
          if (FullYear < 2021) {
            return true
          } else {
            let t = myDate.getDate();
            // 如果想包含本月本月 - 8.64e7 * t 就不需要了,
            // 如果想之前的不能选择把 > 换成 <
            return time.getTime() > (Date.now() - 8.64e7 * t);
          }
          // return false
        },
      },
  }
}

相关文章

网友评论

      本文标题:Element-ui时间选择器禁止选择当月之后的月份

      本文链接:https://www.haomeiwen.com/subject/rrwclrtx.html