vue 时间戳 转 日期

<text style="padding-right: 10px; color: #333; font-size: 28px" slot="value">{{birthdayDate}}</text>

这里名称,不需要定义(实际是函数名)

// 时间戳转日期
        getDate (item) {
            var date = new Date(item)
            var y = 1900 + date.getYear()
            var m = "0" + (date.getMonth() + 1)
            var d = "0" + date.getDate()
            return y + "-" + m.substring(m.length - 2, m.length) + "-" + d.substring(d.length - 2, d.length)
        },

重构:

computed: {
        birthdayDate() {
            return this.getDate(this.user.birthday)
        }
    }

注意:birthdayDate 是转换过的名称,this.getDate(this.date) 转换函数内的名称是原有的名称

猜你喜欢

转载自www.cnblogs.com/wuss/p/10098897.html