天天看点

给element datetimepicker 设置默认当前时间

else里面就是设置默认当前时间15分钟后

watch: {
    row(val) {
      this.liveTime = []
      // 当时间不为空时才回显
      if (val.liveBeginTime && val.liveEndTime) {
        this.liveTime.push(new Date(val.liveBeginTime).format('yyyy-MM-dd HH:mm:ss')) // 回显开始时间
        this.liveTime.push(new Date(val.liveEndTime).format('yyyy-MM-dd HH:mm:ss')) // 回显结束时间
      } else {
      //设置默认时间
        const now = new Date()
        now.addMinutes(15)
        const nowAdd = new Date()
        nowAdd.addHour(1)
        nowAdd.addMinutes(15)
        this.liveTime.push(now.format('yyyy-MM-dd HH:mm:ss')) // 设置当前时间15分钟后为开始时间
        this.liveTime.push(nowAdd.format('yyyy-MM-dd HH:mm:ss')) // 设置当前时间一小时15分钟后为结束时间
        this.row.liveBeginTime = now.format('yyyy-MM-dd HH:mm:ss')
        this.row.liveEndTime = nowAdd.format('yyyy-MM-dd HH:mm:ss')
      }
    }
  },
           

继续阅读