vue开发中遇到的问题的记录
@TOC##在vue中按时间段(本周,本月,本季度,本年)查询?
一,在vue中按时间段(本周,本月,本季度,本年)查询?
- 在src下的utils中建文件dateTimeutils.js,代码如下
/**
* @Created by xfl on 2019/6/10
*/
exports.install = function (Vue, options) {
// 时间格式化
Vue.prototype.format_date = function (DateFor){//全局函数1
let year = DateFor.getFullYear()
let month = DateFor.getMonth() + 1
let day = DateFor.getDate()
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (day >= 0 && day <= 9) {
day = "0" + day;
}
let tmp= year + '-' + month + '-' + day
return tmp
};
/**
* 获取月初,获取 当前月+gap 的月初(若gap为-1,则获取上月初,若gap为1,则获取下月初,
* @param date 若date为空,则获取当前月的
* @param gap
* @returns {string}
*/
Vue.prototype.get_month_first = function (date,gap){
let date1 = new Date();
if(date){
date1= new Date(date);
}
// 获取间隔月
let gapMonth = date1.getMonth() + gap
// 获取间隔月月初
let gapMonthFirstDay=new Date(date1.getFullYear(),gapMonth,1);
let firstDay = this.format_date(gapMonthFirstDay)
console.log(firstDay)
return firstDay
};
// 获取月末
Vue.prototype.get_month_last = function (date,gap){
// gap = gap + 1
let date1 = new Date()
if(date){
date1= new Date(date);
}
// 获取下个月月初
let gapMonth = date1.getMonth()
gapMonth = gapMonth + 1 + gap
let NextMonthFirstDay=new Date(date1.getFullYear(),gapMonth,1)
NextMonthFirstDay = NextMonthFirstDay.getTime() - 1000*60*60*24
let temp = new Date()
temp.setTime(NextMonthFirstDay)
let lastDay = this.format_date(temp)
return lastDay
};
/**
* 获取日期函数,
* @param dateTime 若为空则返回当前日期
* @param gap 若gap=0,则为系统日期,若不为0,则当期日期-gap(当前日期减去gap这个数值的日期)
* @returns {string}
*/
Vue.prototype.get_date = function (dateTime,gap){
let date = new Date()
if(dateTime){
date= new Date(dateTime);
}
date = date.getTime() - 1000*60*60*24*gap
let temp = new Date()
temp.setTime(date)
let day = this.format_date(temp)
return day
};
//获取当前月份
Vue.prototype.get_curMonth = function () {
//获取