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
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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;
}
|
登入後複製
格式化電話號碼
1 2 3 4 5 6 7 8 | const GetPhone = phone => {
let tel = phone.slice(0, 3) + '****' + phone.slice(7, 11);
return tel;
}
module.exports = {
GetNowTime,
GetPhone
}
|
登入後複製
以上是uniapp如何封裝函數的詳細內容。更多資訊請關注PHP中文網其他相關文章!