一、时间转换—时间戳转换年月日
代码如下(示例):
formatDate(cellValue) {
if (cellValue == null || cellValue == "") return "";
var date = new Date(cellValue)
var year = date.getFullYear()
var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
},
二、对象包对象、数组时进行深拷贝
代码如下(示例):
/**
* @desc :对象深度遍历赋值
* @date :
* @params :
* @author : liangdecheng
**/
mergeObject(newObj, dataObj) {
//newObj是需要的对象,dataObj是包含newObj键值对的大对象
let Keys = Object.keys(newObj);
for (let key in dataObj) {
if (Keys.indexOf(key) > -1) {
if (dataObj[key] instanceof Array) {
newObj[key] = [...dataObj[key]];
} else if (dataObj[key] instanceof Object) {
Object.assign(newObj[key], dataObj[key]);
} else {
newObj[key] = dataObj[key];
}
}
}
},