el-date-picker默认快捷键代码(禁掉今日之后的时间)

利用element-uiel-date-picker设置时间组件,如何优化快捷键内容,禁掉今日之后的时间所有时间,下面编程教程网小编给大家详细介绍一下具体代码!

代码如下:

pickerOptions: {
  //时间快捷键
  shortcuts: [{
    text: "昨天",
    onClick(picker) {
     const end = new Date();
     const start = new Date();
     start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
     end.setTime(end.getTime() - 3600 * 1000 * 24 * 1);
     picker.$emit("pick", [start, end]);
    }
  },
  {
    text: "前天",
    onClick(picker) {
     const end = new Date();
     const start = new Date();
     start.setTime(start.getTime() - 3600 * 1000 * 24 * 2);
     end.setTime(end.getTime() - 3600 * 1000 * 24 * 2);
     picker.$emit("pick", [start, end]);
    }
  },
  {
    text: "近一周",
    onClick(picker) {
     const end = new Date();
     const start = new Date();
     start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
     picker.$emit("pick", [start, end]);
    }
  },
  {
    text: "近一个月",
    onClick(picker) {
     const end = new Date();
     const start = new Date();
     start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
     picker.$emit("pick", [start, end]);
    }
  },
  {
    text: "近三个月",
    onClick(picker) {
     const end = new Date();
     const start = new Date();
     start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
     picker.$emit("pick", [start, end]);
    }
  },
  {
    text: "近半年",
    onClick(picker) {
     const end = new Date();
     const start = new Date();
     start.setTime(start.getTime() - 3600 * 1000 * 24 * 180);
     picker.$emit("pick", [start, end]);
    }
  },
  {
    text: "近一年",
    onClick(picker) {
     const end = new Date();
     const start = new Date();
     start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
     picker.$emit("pick", [start, end]);
    }
  }],

  //禁掉今日之后的时间
  disabledDate(time) {
   return time.getTime() > Date.now();
  }
},
以上是编程学习网小编为您介绍的“el-date-picker默认快捷键代码(禁掉今日之后的时间)”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。

本文标题为:el-date-picker默认快捷键代码(禁掉今日之后的时间)

基础教程推荐