This article mainly introduces relevant information about the detailed introduction of the modularization of WeChat mini programs. Friends who need it can refer to it
Modularization is to extract some common things and put them into a file. module.exports to expose interfaces. When we first created the project, there was a util.js file that was modularized.
/** * 處理具體業(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 }
Usage method:
//導(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)) }) }) } })
For more detailed introduction to the modularization of WeChat mini programs and related articles, please pay attention to the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
