Skip to content

Commit 56febcd

Browse files
committed
fix(BlogPosts): 禁用获取文章数据时的token验证
在获取文章数据时,添加`withToken: false`选项以避免不必要的token验证。同时,修复了`posts()`可能为`null`时的类型检查问题。
1 parent 38be91a commit 56febcd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

blog-web/src/components/solid/BlogPosts.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function formatDate(dateString: string) {
2929
// 获取文章数据的函数
3030
async function fetchPosts(): Promise<Post[]> {
3131
try {
32-
const response = await http.get<Post[]>("/posts");
32+
const response = await http.get<Post[]>("/posts", { withToken: false });
3333

3434
// 检查响应格式,直接处理返回的数组数据
3535
if (response && Array.isArray(response)) {
@@ -58,7 +58,7 @@ export default function BlogPosts() {
5858
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 my-8">
5959
<Show when={!posts.loading} fallback={<div class="col-span-full text-center">加载中...</div>}>
6060
<Show
61-
when={posts() && posts().length > 0}
61+
when={posts() && posts()!.length > 0}
6262
fallback={
6363
<div class="col-span-full text-center py-12">
6464
<div class="alert alert-info shadow-lg max-w-md mx-auto">

0 commit comments

Comments
 (0)