Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit30f5df2

Browse files
committed
公共方法
1 parentfc2e779 commit30f5df2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

‎src/utils/index.js‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
constisObject=obj=>typeofobj==='object'&&obj!=null
2+
13
exportdefault{
24
/**
35
* 判断一个对象是否在数组里面
@@ -42,6 +44,41 @@ export default {
4244
})
4345
returnarr2
4446
},
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+
},
4582
}
4683
functionformatDate(date){
4784
varmyyear=date.getFullYear()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp