fake_shop/app/tab/page.jsx

33 lines
757 B
JavaScript

import React from "react";
import Product from "@/components/Product";
async function getProducts() {
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/products`, {
cache: "no-store",
});
if (!res.ok) {
throw new Error("获取商品列表失败");
}
return res.json();
}
export default async function Feed() {
const products = await getProducts();
return (
<div className="p-4 grid grid-cols-1 gap-4">
{products.map((product) => (
<Product
key={product._id}
id={product._id}
title={product.title}
price={product.price}
sales={product.sales}
imageUrl={product.imageUrl}
isVip={product.isVip}
/>
))}
</div>
);
}