React/JS 未在 React array.map() 参数上显示可能性(智能感知)VSCODE

问题描述 投票:0回答:1

我有如下的 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>
     );
   }

我已经为此苦苦挣扎了一段时间,但还没有找到方法。

javascript html reactjs intellisense
1个回答
0
投票

试试这个:

   export const products = [
   {
     _id: "1",
      name: "Airpods Wireless Bluetooth Headphones",
     image: "/images/airpods.jpg",
   },
   ];

执行此操作后,将产品变量导入 Home.JS

它会起作用的。

© www.soinside.com 2019 - 2024. All rights reserved.