Home  >  Article  >  Web Front-end  >  How uniapp encapsulates functions

How uniapp encapsulates functions

coldplay.xixi
coldplay.xixiOriginal
2020-12-18 14:42:443804browse

Uniapp encapsulation function method: 1. Get the current time, the code is [hour = date.getHours() < 10 ? "0" date.getHours() : date.getHours()]; 2. Format phone number.

How uniapp encapsulates functions

The operating environment of this tutorial: windows7 system, uni-app2.5.1 version. This method is suitable for all brands of computers.

Recommended (free): uni-app development tutorial

Uniapp encapsulation function method:

Get the current time in the format 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 + &#39;-&#39; + month + &#39;-&#39; + day + &#39; &#39; + hour + &#39;:&#39; + minute + &#39;:&#39; + second;
return timer;
}

Format phone number

const GetPhone = phone => {
let tel = phone.slice(0, 3) + &#39;****&#39; + phone.slice(7, 11);
return tel;
}
module.exports = {
GetNowTime,
GetPhone
}

The above is the detailed content of How uniapp encapsulates functions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn