From 7d6e056e6bf37b757553b118602d8fdc3da4b755 Mon Sep 17 00:00:00 2001 From: tone <3341154833@qq.com> Date: Sat, 31 Aug 2024 15:05:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8D=9A=E5=AE=A2=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E9=87=8F=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tonecn/src/lib/formateTimes.ts | 9 +++++++++ tonecn/src/views/Blog.vue | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tonecn/src/lib/formateTimes.ts diff --git a/tonecn/src/lib/formateTimes.ts b/tonecn/src/lib/formateTimes.ts new file mode 100644 index 0000000..5109d30 --- /dev/null +++ b/tonecn/src/lib/formateTimes.ts @@ -0,0 +1,9 @@ +function formateTimes(times: number) { + if (times < 10000)// 一万以内直接显示 + return times; + if (times < 10000 * 10000)// 一亿以内加上 万 + return (times / 10000).toFixed(1) + '万' + return (times / 10000 / 10000).toFixed(1) + '亿' +} + +export { formateTimes }; \ No newline at end of file diff --git a/tonecn/src/views/Blog.vue b/tonecn/src/views/Blog.vue index 33229e8..7beb0d9 100644 --- a/tonecn/src/views/Blog.vue +++ b/tonecn/src/views/Blog.vue @@ -2,6 +2,7 @@ import { request } from '@/lib/request'; import { onMounted, reactive, ref } from 'vue'; import { timestampToString } from '../lib/timestampToString' +import { formateTimes } from '@/lib/formateTimes'; const loadStatus = ref(0); const blogList = reactive([]); @@ -30,7 +31,8 @@ onMounted(async () => {