js中new Date().format()方法不可用问题

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
</html>

<script type="javascript">
    Date.prototype.format = function(format){
        if((format = "" || format == undefined)){
            format ="yyyy-mm-dd h:m:s"
        }
        let conf =['yyyy','mm', 'dd','h','m','s','S'];
        let arr = {
            'yyyy':this.getFullYear(),
            'mm':this.getMonth() +1,
            'dd':this.getDate(),
            'h':this.getHours(),
            'm':this.getMinutes(),
            's':this.getSeconds(),
            'S':this.getMilliseconds(),
        };
        conf.forEach(function(item){
            format= format.replace(item,arr[item])
        });
        return format;
    };
    // 添加到Vue原型上
    Vue.prototype.$date = function (value) {
        return new Date();
    };
    // 使用
    new Vue({
        el: '#app',
        data:function(){
            return {
                time:46545
            }
        }
        computed:{
            time_str(){
                return   this.$date(this.time).format();
            }
        }
    });
</script>
This entry was posted in js, Vue. Bookmark the permalink.

发表回复