首页 > 编程知识 正文

微信小程序wxss样式,小程序开发文档

时间:2023-05-04 11:34:11 阅读:230498 作者:4043

微信小程序wxs文件如何使用 第一步 创建.wxs文件第二步 在.wxml文件引入format.wxs文件第三步 使用wxs

wxs是微信小程序为了减少逻辑层和视图层之间的通信次数,格式化操作一般在wxs文件上进行。

第一步 创建.wxs文件 // format.wxs文件 我这里wxs文件名字为formatmodule.exports.ddms = function(second) { var second = typeof second === 'undefined' ? 0 : second; // 格式化时间 var day = Math.floor(second / 3600 / 24).toString(); if (day.length == 1) { // 天 day = '0' + day; } var hour = Math.floor((second - day * 3600 * 24) / 3600).toString(); if (hour.length == 1) { // 小时 hour = '0' + hour } var min = Math.floor((second - day * 3600 *24 - hour * 3600) / 60).toString(); if (min.length == 1) { // 分钟 min = '0' + min } // 秒位 var sec = second - day * 3600 * 24 - hour * 3600 - min*60; var sec = Math.floor(sec).toString(); if (sec.length == 1) { sec = '0' + sec; } return day + '天' + hour + '时' + min + '分' + sec + '秒';}module.exports.formatSeconds = function(second) { // 把秒转换为正整数 var second = typeof second === 'undefined' ? 0 : parseInt(second); // 时 var h = Math.floor(second / 3600) < 10 ? '0' + Math.floor(second / 3600) : Math.floor(second / 3600); // 分 var m = Math.floor((second / 60 % 60)) < 10 ? '0' + Math.floor((second / 60 % 60)) : Math.floor((second / 60 % 60)); // 秒 var s = Math.floor((second % 60)) < 10 ? '0' + Math.floor((second % 60)) : Math.floor((second % 60)); // return h + ':' + m + ':' + s; return h +":"+ m +":" + s;}module.exports.formatSecondsTwo = function(second) { // 把秒转换为正整数 var second = typeof second === 'undefined' ? 0 : parseInt(second); // 时 var h = Math.floor(second / 3600) < 10 ? '0' + Math.floor(second / 3600) : Math.floor(second / 3600); // 分 var m = Math.floor((second / 60 % 60)) < 10 ? '0' + Math.floor((second / 60 % 60)) : Math.floor((second / 60 % 60)); // 秒 var s = Math.floor((second % 60)) < 10 ? '0' + Math.floor((second % 60)) : Math.floor((second % 60)); // return h + ':' + m + ':' + s; return [h, m, s];}module.exports.format2HMS = function(secondTime) { var minuteTime; var hourTime; if (secondTime > 60) { minuteTime = parseInt(secondTime / 60); if (minuteTime > 60) { hourTime = parseInt(minuteTime / 60); minuteTime = parseInt(minuteTime % 60); return hourTime + '时' + minuteTime + '分'; if (hourTime > 24) { return parseInt(secondTime / (1000 * 60 * 60 * 24)) + '天' } } else { return minuteTime + '分'; } } else { return secondTime + '秒'; }}// 把金额小数点后两位如果是00,则省略module.exports.replacePointZeroToNone = function(value) { var regexp = getRegExp('.00', 'g'); return value.replace(regexp, '');} 第二步 在.wxml文件引入format.wxs文件 <!-- 引入方式,其中module是为wxs文件起个名字 --><wxs src="../../common/wxs/format.wxs" module="format" /> 第三步 使用wxs // replacePointZeroToNone为format.js里面的一个方法{{ format.replacePointZeroToNone() }}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。