uniapp封装函数的方法:1、获取当前时间,代码为【hour = date.gethours() < 10 ? 0 + date.gethours() : date.gethours()】;2、格式化电话号码。
本教程操作环境:windows7系统、uni-app2.5.1版本,该方法适用于所有品牌电脑。
推荐(免费):uni-app开发教程
uniapp封装函数的方法:
获取当前时间,格式yyyy-mm-dd hh:mm:ss
const getnowtime = time => {var date = time,year = date.getfullyear(),month = date.getmonth() + 1,day = date.getdate(),hour = date.gethours() < 10 ? "0" + date.gethours() : date.gethours(),minute = date.getminutes() < 10 ? "0" + date.getminutes() : date.getminutes(),second = date.getseconds() < 10 ? "0" + date.getseconds() : date.getseconds();month >= 1 && month <= 9 ? (month = "0" + month) : "";day >= 0 && day <= 9 ? (day = "0" + day) : "";var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;return timer;}
格式化电话号码
const getphone = phone => {let tel = phone.slice(0, 3) + '****' + phone.slice(7, 11);return tel;}module.exports = {getnowtime,getphone}
以上就是uniapp如何封装函数的详细内容。