Skip to content

Commit 70db622

Browse files
committed
全局过滤器新增日期时间格式过滤
1 parent b223757 commit 70db622

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dependencies": {
1111
"@xunlei/vue-context-menu": "^1.0.2",
1212
"axios": "^0.19.0",
13+
"dayjs": "^1.8.33",
1314
"babel-polyfill": "^6.26.0",
1415
"core-js": "^3.4.3",
1516
"element-ui": "^2.13.2",

src/filters/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
import Vue from 'vue';
22

3+
/**
4+
* 格式化时间
5+
*/
6+
Vue.filter('formatDate', function (value, template) {
7+
if (value == null) {
8+
return null;
9+
}
10+
return dayjs(value).format(!!template ? template : 'YYYY-MM-DD HH:mm:ss')
11+
});
312
// 数字加千分符
413
Vue.filter('T', value => Number(value).toLocaleString());

src/main.js

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Vue.use(ViewUI);
1818
// 引入全局工具函数
1919
import * as utils from "./utils";
2020
// 引入全局过滤器
21+
import * as filters from '@/filters';
22+
Object.keys(filters).forEach((key) => {
23+
Vue.filter(key, filters[key]);
24+
});
2125
// import '@/filters'
2226
import "font-awesome/scss/font-awesome.scss";
2327
// 在入口处引入模拟的假数据

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -2609,6 +2609,11 @@ dashdash@^1.12.0:
26092609
dependencies:
26102610
assert-plus "^1.0.0"
26112611

2612+
dayjs@^1.8.33:
2613+
version "1.10.4"
2614+
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.10.4.tgz#8e544a9b8683f61783f570980a8a80eaf54ab1e2"
2615+
integrity sha512-RI/Hh4kqRc1UKLOAf/T5zdMMX5DQIlDxwUe3wSyMMnEbGunnpENCdbUgM+dW7kXidZqCttBrmw7BhN4TMddkCw==
2616+
26122617
de-indent@^1.0.2:
26132618
version "1.0.2"
26142619
resolved "https://registry.yarnpkg.com/de-indent/-/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d"

0 commit comments

Comments
 (0)