vue 時間戳 轉 日期

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

這裏名稱,不須要定義(實際是函數名)函數

// 時間戳轉日期
add0 (m) {
return m < 10 ? '0' + m:m
},
getDate (item) {
var time = new Date(item) 
var year = time.getFullYear()
var month = time.getMonth() + 1
var date = time.getDate()
return year + '-' + this.add0(month) + '-' + this.add0(date)
}

重構:this

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

注意:birthdayDate 是轉換過的名稱,this.getDate(this.date) 轉換函數內的名稱是原有的名稱spa

 -------------------------------------code

轉時間戳blog

getTimestamp (mytime){
let dateTmp = mytime.replace(/-/g,'/')
return Date.parse(dateTmp)
},

get

相關文章
相關標籤/搜索