国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

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

2019-11-20 08:52:16
字體:
供稿:網(wǎng)友

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

 /** * 處理具體業(yè)務邏輯 */function formatTime(date) { //獲取年月日 var year = date.getFullYear() var month = date.getMonth() + 1 var day = date.getDate() //獲取時分秒 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}/** * 模塊化導出暴露接口 */module.exports = { formatTime: formatTime}

使用方式:

//導入模塊化方式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)) }) }) }})

相關文章:

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 丹巴县| 应用必备| 合山市| 清新县| 莱芜市| 夏邑县| 大洼县| 枣强县| 云林县| 万山特区| 阿拉善右旗| 定安县| 灵台县| 临汾市| 将乐县| 芦山县| 扶余县| 五原县| 江城| 开阳县| 得荣县| 贡嘎县| 三河市| 彝良县| 花莲市| 宜州市| 尼玛县| 比如县| 长汀县| 大新县| 且末县| 丰宁| 沛县| 瓮安县| 汶川县| 中西区| 延安市| 囊谦县| 古蔺县| 平昌县| 禄劝|