fix: 商品生图助手容错 — API 返回非数组时设空数组避免崩溃

This commit is contained in:
Sisyphus 2026-06-29 17:33:21 +08:00
parent d8d49f7e88
commit 785db9277d

View File

@ -67,7 +67,10 @@ export default function ImagePage() {
useEffect(() => { useEffect(() => {
fetch(API) fetch(API)
.then(r => r.json()) .then(r => r.json())
.then(setImages) .then(data => {
setImages(Array.isArray(data) ? data : [])
})
.catch(() => setImages([]))
.finally(() => setLoading(false)) .finally(() => setLoading(false))
}, []) }, [])