我有如下的 products.js:
const products = [
{
_id: "1",
name: "Airpods Wireless Bluetooth Headphones",
image: "/images/airpods.jpg",
},
];
我有 Home.js :
export default function HomeScreen() {
return (
<div>
<h1>Lasted Production</h1>
<Row>
{products.map((product) => (
<Col key={product._id} sm={12} md={6} lg={4} xl={3}>
<Product product={product} />
</Col>
))}
</Row>
</div>
);
}
在下面的另一个文件 Product.js 上,当我在 {product} 之后放置点时,我期望 {product._id},{product.name},{product.image} 自动弹出作为智能感知,但它不起作用
export default function Product({ product }) {
return (
<Card.Body>
<a href={`/product/${product._id}`}>
<Card.Title as="div">
<strong>{product.name}</strong> //.name can only manual input,no intellisense popup
</Card.Title>
</Card.Text>
</Card.Body>
);
}
我已经为此苦苦挣扎了一段时间,但还没有找到方法。
试试这个:
export const products = [
{
_id: "1",
name: "Airpods Wireless Bluetooth Headphones",
image: "/images/airpods.jpg",
},
];
执行此操作后,将产品变量导入 Home.JS
它会起作用的。