欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序 (六)模塊化詳細(xì)介紹

 更新時(shí)間:2016年09月27日 11:01:47   作者:順子_RTFSC  
這篇文章主要介紹了微信小程序模塊化詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下

模塊化也就是將一些通用的東西抽出來放到一個(gè)文件中,通過module.exports去暴露接口。我們在最初新建項(xiàng)目時(shí)就有個(gè)util.js文件就是被模塊化處理時(shí)間的

 /**
 * 處理具體業(yè)務(wù)邏輯
 */
function formatTime(date) {
 //獲取年月日
 var year = date.getFullYear()
 var month = date.getMonth() + 1
 var day = date.getDate()

 //獲取時(shí)分秒
 var hour = date.getHours()
 var minute = date.getMinutes()
 var second = date.getSeconds();

 //格式化日期
 return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

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

/**
 * 模塊化導(dǎo)出暴露接口
 */
module.exports = {
 formatTime: formatTime
}

使用方式:

//導(dǎo)入模塊化方式
var util = require('../../utils/util.js')
Page({
 data: {
 logs: []
 },
 onLoad: function () {
 this.setData({
 logs: (wx.getStorageSync('logs') || []).map(function (log) {
 // 通過暴露的接口調(diào)用模塊化方法
 return util.formatTime(new Date(log))
 })
 })
 }
})



相關(guān)文章:

hello WeApp                      icon組件
Window 
                            text組件                                switch組件
tabBar底部導(dǎo)航                 progress組件                        action-sheet
應(yīng)用生命周期                    button組件                            modal組件
頁面生命周期
                    checkbox組件                       toast組件
模塊化詳                           form組件詳                            loading 組件
數(shù)據(jù)綁定
                           input 組件                             navigator 組件
View組件                          picker組件                             audio 組件
scroll-view組件                 radio組件                              video組件
swiper組件                        slider組件                              Image組件

相關(guān)文章

最新評(píng)論