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 50 51 52 53 54 55 56 57 58 59 60 61 62
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="../vue.min.js"></script> <style> #app { background-color: #333333; color: #fff; font-size: 66px; text-align: center; } </style> </head> <body> <div id="app"> {{date | formatDate }} </div>
<script> function padDate(value) { return value < 10 ? "0" + value : value; }
var vm = new Vue({ el: '#app', 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 hour = padDate(date.getHours()); var minute = padDate(date.getMinutes()); var second = padDate(date.getSeconds());
return year + '-' + month + '-' + day + '-' + '-' + hour + ':' + minute + ':' + second; } }, mounted:function() { var currentVmObj = this; this.trimer = setInterval(function() { currentVmObj.date = new Date(); },1000); }, beforeDestroy:function() { if(this.timer != null) { clearInterval(this.timer) } } }) </script> </body> </html>
|