其他分享
首页 > 其他分享> > element ui 日期时间组件默认展示最近一周

element ui 日期时间组件默认展示最近一周

作者:互联网

<el-form-item label="出库日期:">         <el-date-picker           type="daterange"           range-separator="-"           @change="(e) => {changeTime({startItem: 'outWarehouseStartTime',endItem: 'outWarehouseEndTime',value: e})}"           v-model="outWarehouseTimeLine"           start-placeholder="出库开始日期"           end-placeholder="出库结束日期"           value-format="yyyy-MM-dd"         ></el-date-picker>       </el-form-item>  
 import formatTime from "@/utils/formatTime.js"



 data() {
    return {
      outWarehouseTimeLine : [],  
    };
  },
mounted() {
    let times = 86400000 * 7 //一整周的毫秒数
    let curTime = formatTime(new Date().getTime()).split(' ')[0]
    let beforeTime = formatTime(new Date().getTime() - times).split(' ')[0]
    this.outWarehouseTimeLine = [beforeTime, curTime]
    this.changeTime({startItem: 'outWarehouseStartTime',endItem: 'outWarehouseEndTime',value: [beforeTime, curTime]})

  },

    changeTime(e){
      this.formData[e.startItem] = e.value ? e.value[0] + ' 00:00:00' : ''
      this.formData[e.endItem] = e.value ? e.value[1] + ' 23:59:59' : ''
    },

 

formatTime.js

function add0(m){return m<10?'0'+m:m }
function formatTime(time){
  //shijianchuo是整数,否则要parseInt转换
  var time = new Date(time);
  var y = time.getFullYear();
  var m = time.getMonth()+1;
  var d = time.getDate();
  var h = time.getHours();
  var mm = time.getMinutes();
  var s = time.getSeconds();
  return y+'-'+ add0(m) +'-'+ add0(d)+' '+ add0(h)+':'+ add0(mm)+':'+ add0(s);
}

export default formatTime

 

标签:00,let,endItem,value,element,formatTime,curTime,组件,ui
来源: https://www.cnblogs.com/shuihanxiao/p/16419043.html