码迷,mamicode.com
首页 > 微信 > 详细

小程序调模块化调用

时间:2018-08-07 13:09:00      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:seconds   format   module   get   map   require   storage   day   date   

util.js

const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join(/) +   + [hour, minute, second].map(formatNumber).join(:)
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : 0 + n
}

module.exports = {
  formatTime: formatTime
}
//logs.js
const util = require(../../utils/util.js)

Page({
  data: {
    logs: []
  },
  onLoad: function () {
    this.setData({
      logs: (wx.getStorageSync(logs) || []).map(log => {
        return util.formatTime(new Date(log))
      })
    })
  }
})

 

小程序调模块化调用

标签:seconds   format   module   get   map   require   storage   day   date   

原文地址:https://www.cnblogs.com/hzx-5/p/9435620.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!