cssjshtml vue.js 时间格式化

葫芦的运维日志

下一篇 搜索 上一篇

2018/10/14 00:21


页面展现:

源码: 

<!--
# @Time    : 2018/10/13 上午12:39
# @Author  : BrownWang
# @Email   : 277215243@qq.com
# @File    : vue3.html
# @Software: PyCharm -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
<h1 style='color:yellow;'>{{ date | formatDate }}</h1>
</div>
<script src="/static/js/vue.min.js"></script>
<script>
var padDate = function(value){
    return value < 10 ? '0'+value : value;
};
    var app=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 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);
            },
        beforeDestroy: function() {
            if (this.timer){
                clearInterval(this.timer);
            }
        }
    })
</script>
</body>
</html>

 

葫芦的运维日志

打赏

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2019 王梓 打赏联系方式 陕ICP备17005322号