-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (46 loc) · 1.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const ClockPlugin = {
install(_Vue) {
const vm = new _Vue({
data() {
return {
now: Date.now()
}
},
computed: {
time() {
let d = new Date(this.now);
return `${d.getHours()}:${d.getMinutes()}`;
},
dateString() {
return new Date(this.now).toDateString();
},
startOfDay() {
let start = new Date(this.now);
start.setHours(0,0,0,0);
return start;
},
endOfDay() {
var end = new Date(this.now);
end.setHours(23,59,59,999);
return end;
}
},
methods: {
update() {
this.now = Date.now()
}
},
created() {
let d = new Date(this.now);
setTimeout(() => {
this.update();
setInterval(() => this.update(), 60 * 1000);
},
(60 - d.getSeconds()) * 1000
);
}
});
_Vue.prototype.$clock = vm;
}
};
export default ClockPlugin;