js 向数组中增加json元素、日期组件一个月的范围


//alert(JSON.stringify(this.gasList))

一、js 向数组中增加json元素?

for (let i = 0; i < list.length; i++) {
var aa = {
“mediaValue” : list[i],
“mediaLabel” : list[i],
}
this.checkBoxList.push(aa)
}

二、日期组件一个月的范围

  1. 在js文件中加入以下代码:
//获取当前时间
export const getPastHalfYear = () => {
  //先获取当前时间
  const curDate = (new Date()).getTime()
  //将半年的时间单位换算成毫秒
  const halfYear = 365 / 12 * 24 * 3600 * 1000
  const pastResult = curDate - halfYear //半年前的时间
  // 日期函数,定义起点为半年前
  const pastDate = new Date(pastResult)
  const pastMonth = pastDate.getMonth() + 1
  const pDate = pastDate.getDate()
  return pastDate.getFullYear() + '-' + (pastMonth >= 10 ? pastMonth : '0' + pastMonth) +
    '-' + (pDate >= 10 ? pDate : '0' + pDate)
}

export const getDateStartEnd = () =>{
  let arr = []
  var date = new Date(new Date().getTime());
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var day = date.getDate();
  if (month < 10) {
    month = month;
  }
  if (day < 10) {
    day = day;
  }
  var nowDate = year + "-" + month + "-" + day;
  // const nowDate = year + month + day;
  // const end = year + month + day
  const start = getPastHalfYear()
  arr.push(start)
  arr.push(nowDate)
  return arr
}
  1. 在vue页面中引入
 import {getDateStartEnd} from '@/lib/util'
  1. 做判断,日期变量长度是否小于3
 /* -------------------------查询相关 begin------------------------- */
      convertQueryParam() {

        //判断日期范围是《 5
        if (this.queryForm.czDateTimeRange.length < 3) {
          this.queryForm.czDateTimeRange = getDateStartEnd();
        }

        let czDateTimeArray = dateTimeRangeConvert(this.queryForm.czDateTimeRange);
        // let createTimeArray = dateTimeRangeConvert(this.queryForm.createTimeRange);
        // let updateTimeArray = dateTimeRangeConvert(this.queryForm.updateTimeRange);
        return {
          ...this.queryForm,
          czDateBegin: czDateTimeArray[0],
          czDateeEnd: czDateTimeArray[1],
          // createTimeBegin:createTimeArray[0],
          // createTimeEnd:createTimeArray[1],
          // updateTimeBegin:updateTimeArray[0],
          // updateTimeEnd:updateTimeArray[1]
        };
      },
  1. 生命日期变量:
//搜索表单
        queryForm: {
          czDateTimeRange: ["", ""],
		}
  1. 日期组件
       <span>加气时间 :
                    <DatePicker
                      placeholder="选择加气日期范围"
                      split-panels
                      style="width: 200px"
                      type="daterange"
                      v-model="queryForm.czDateTimeRange"
                    ></DatePicker>
       </span>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值