• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
不见花落
博客园    首页    新随笔    联系   管理    订阅  订阅
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)
}

重构:

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

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

 -------------------------------------

转时间戳

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

posted on 2018-12-10 20:30  不见花落  阅读(3123)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3