-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvue-filter-code.html
More file actions
49 lines (49 loc) · 1.44 KB
/
Copy pathvue-filter-code.html
File metadata and controls
49 lines (49 loc) · 1.44 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="dateId">
{{date | formatDate}}
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
var padDate = function (value) {
return value < 10 ? '0' + value : value;
}
var vm = new Vue({
el: '#dateId',
data: {
date: new Date()
},
filters: {
formatDate: function (value) {
var date = new Date(value);
var year = date.getFullYear();
var month = padDate(date.getMonth() + 1);
var day = padDate(date.getDate());
var hours = padDate(date.getHours());
var minutes = padDate(date.getMinutes());
var seconds = padDate(date.getSeconds());
return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
}
},
mounted: function() {
var _this = this;
this.timer = setInterval(function () {
_this.date = new Date();
}, 1000);
},
beforeDestory: function() {
if(this.timer) {
clearInterval(this.timer);
}
}
})
</script>
</html>