工具函数:
export default {
methods: {
getDay(day) {
var today = new Date();
var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
today.setTime(targetday_milliseconds); //注意,这行是关键代码
var tYear = today.getFullYear();
var tMonth = today.getMonth();
var tDate = today.getDate();
tMonth = this.doHandleMonth(tMonth + 1);
tDate = this.doHandleMonth(tDate);
return tYear + "-" + tMonth + "-" + tDate;
},
doHandleMonth(month) {
var m = month;
if (month.toString().length == 1) {
m = "0" + month;
}
return m
},
// tools
isOkArray(val) {
return val && Array.isArray(val) && val.length != 0
},
/**
* @function【common function】
* 添加多项的加、减按钮操作
* @param {*} item 要删除的项
* @param {Number} index 要删除的项的索引
*/
removeDomain(item, index, target) {
console.log(index)
this.form[target].splice(index, 1)
},
addDomain(item, target, keys) {
// this.obj = Object.assign({},this.obj,{a:1,b:2});
this.form[target].push({
key: Date.now(),
...keys
})
},
}
}
使用:
getDay(0) //今天
getDay(-1) //近一天
getDay(-7) //近一周
getDay(-30) //近一个月
标签:index,函数,val,month,getDay,var,时间,工具,today
From: https://www.cnblogs.com/djsz3y/p/17383439.html