|
| 1 | +constisObject=obj=>typeofobj==='object'&&obj!=null |
| 2 | + |
1 | 3 | exportdefault{ |
2 | 4 | /** |
3 | 5 | * 判断一个对象是否在数组里面 |
@@ -42,6 +44,41 @@ export default { |
42 | 44 | }) |
43 | 45 | returnarr2 |
44 | 46 | }, |
| 47 | + |
| 48 | +cloneDeep(source){ |
| 49 | +if(!isObject(source))returnsource// 非对象返回自身 |
| 50 | +consttarget=Array.isArray(source) ?[] :{} |
| 51 | +for(varkeyinsource){ |
| 52 | +if(Object.prototype.hasOwnProperty.call(source,key)){ |
| 53 | +if(isObject(source[key])){ |
| 54 | +target[key]=this.cloneDeep(source[key])// 注意这里 |
| 55 | +}else{ |
| 56 | +target[key]=source[key] |
| 57 | +} |
| 58 | +} |
| 59 | +} |
| 60 | +returntarget |
| 61 | +}, |
| 62 | + |
| 63 | +// getDay(0);//当天日期 getDay(-7);//7天前日期 getDay(0);//当天日期 getDay(-3);//3天前日期 |
| 64 | +getDay(day){ |
| 65 | +vartoday=newDate() |
| 66 | +vartargetday_milliseconds=today.getTime()+1000*60*60*24*day |
| 67 | +today.setTime(targetday_milliseconds)//注意,这行是关键代码 |
| 68 | +vartYear=today.getFullYear() |
| 69 | +vartMonth=today.getMonth() |
| 70 | +vartDate=today.getDate() |
| 71 | +tMonth=this.doHandleMonth(tMonth+1) |
| 72 | +tDate=this.doHandleMonth(tDate) |
| 73 | +returntYear+'-'+tMonth+'-'+tDate |
| 74 | +}, |
| 75 | +doHandleMonth(month){ |
| 76 | +varm=month |
| 77 | +if(month.toString().length==1){ |
| 78 | +m='0'+month |
| 79 | +} |
| 80 | +returnm |
| 81 | +}, |
45 | 82 | } |
46 | 83 | functionformatDate(date){ |
47 | 84 | varmyyear=date.getFullYear() |
|