fix: 修复日期显示NaN年NaN月NaN日的问题
- formatDate兼容date和createdAt两种字段名 - 增加空值和无效日期防御 - 同步news.json分类数据(之前category全为null) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
这个提交包含在:
+4
-2
@@ -14,7 +14,7 @@
|
||||
<!-- 文章元信息 -->
|
||||
<div class="article-meta">
|
||||
<span class="article-category">{{ article.category }}</span>
|
||||
<span class="article-date">{{ formatDate(article.date) }}</span>
|
||||
<span class="article-date">{{ formatDate(article.date || article.createdAt) }}</span>
|
||||
<span class="article-author">作者:{{ article.author }}</span>
|
||||
</div>
|
||||
|
||||
@@ -230,7 +230,9 @@ const nextArticle = computed(() => currentIndex.value < allArticles.value.length
|
||||
const otherArticles = allArticles
|
||||
|
||||
function formatDate(dateStr) {
|
||||
const d = new Date(dateStr)
|
||||
if (!dateStr) return ''
|
||||
const d = new Date(dateStr.includes('T') ? dateStr : dateStr + 'T00:00:00')
|
||||
if (isNaN(d.getTime())) return ''
|
||||
return `${d.getFullYear()}年${d.getMonth() + 1}月${d.getDate()}日`
|
||||
}
|
||||
</script>
|
||||
|
||||
+4
-2
@@ -51,7 +51,7 @@
|
||||
</div>
|
||||
<div class="blog-card__body">
|
||||
<div class="blog-card__meta">
|
||||
<span class="blog-card__date">{{ formatDate(article.date) }}</span>
|
||||
<span class="blog-card__date">{{ formatDate(article.date || article.createdAt) }}</span>
|
||||
<span class="blog-card__author">{{ article.author }}</span>
|
||||
</div>
|
||||
<h2 class="blog-card__title">{{ article.title }}</h2>
|
||||
@@ -136,7 +136,9 @@ function getCategoryCount(key) {
|
||||
}
|
||||
|
||||
function formatDate(dateStr) {
|
||||
const d = new Date(dateStr)
|
||||
if (!dateStr) return ''
|
||||
const d = new Date(dateStr.includes('T') ? dateStr : dateStr + 'T00:00:00')
|
||||
if (isNaN(d.getTime())) return ''
|
||||
return `${d.getFullYear()}年${d.getMonth() + 1}月${d.getDate()}日`
|
||||
}
|
||||
</script>
|
||||
|
||||
在新工单中引用
屏蔽一个用户