123456789101112131415161718192021222324 |
- import Vue from 'vue'
- const common = {
- install(Vue) {
- // 手机号码格式成秘文形式 格式为137****3151
- String.prototype.$formatPhone = function () {
- return this.replace(/(\d{3})\d+(\d{4})/, '$1****$2')
- }
- // 格式化时间 格式为 2023-10-02 12:00:00
- Date.prototype.$formatTime = function () {
- var Y = this.getFullYear() + '-';
- var M = (this.getMonth() + 1 < 10 ? '0' + (this.getMonth() + 1) : this.getMonth() + 1) + '-';
- var D = (this.getDate() < 10 ? '0' + this.getDate() : this.getDate()) + ' ';
- var h = (this.getHours() < 10 ? '0' + this.getHours() : this.getHours()) + ':';
- var m = (this.getMinutes() < 10 ? '0' + this.getMinutes() : this.getMinutes()) + ':';
- var s = this.getSeconds() < 10 ? '0' + this.getSeconds() : this.getSeconds();
- return Y + M + D + h + m + s;
- }
- }
- }
- Vue.use(common)
|