Javascript 如何正确导出对象?

Javascript 如何正确导出对象?,javascript,reactjs,debugging,Javascript,Reactjs,Debugging,我想知道我是如何错误地导出对象的?在我看来,我看到了这个错误:/src/context.js 尝试导入错误:“detailProduct”未从“./data”导出。 在控制台中,我确实看到对象被正确填充,但由于某种原因,由于前面提到的错误,它不会呈现我的视图。我做错了什么 export const storeProducts = [ { id: 1, title: "Crusk Beanie (black)", img: "img/CruskipBlackBeanie

我想知道我是如何错误地导出对象的?在我看来,我看到了这个错误:
/src/context.js
尝试导入错误:“detailProduct”未从“./data”导出。

在控制台中,我确实看到对象被正确填充,但由于某种原因,由于前面提到的错误,它不会呈现我的视图。我做错了什么

export const storeProducts = [
  {
    id: 1,
    title: "Crusk Beanie (black)",
    img: "img/CruskipBlackBeanie.png",
    price: 1,
    company: "Cruskip",
    info:
        "Winter's right around the corner, get your beanie today!",
    inCart: false,
    count: 0,
    total: 0
  },
  {
    id: 3,
    title: "Cruskip Short Sleeve T-shirt",
    img: "img/CruskipWhiteShortSleeve.jpg",
    price: 8,
    company: "Cruskip",
    info:
        "Exclusive Cruskip white t-shirts!",
    inCart: false,
    count: 0,
    total: 0
  },
];

let detailProduct = {};

storeProducts.forEach((arrayItem) => {
  detailProduct = {
    id: arrayItem.id,
    title: arrayItem.title,
    img: arrayItem.img,
    price: arrayItem.price,
    company: arrayItem.company,
    info: arrayItem.info,
    inCart: arrayItem.inCart,
    count: arrayItem.count,
    total: arrayItem.total
  };
  console.log(arrayItem);
});

export default detailProduct;

您可能使用大括号导入它,但对于
default
exports:

// This will work
import detailProduct from './data';

// This won't
import { detailProduct } from '.data';
另一方面,由于
storeProducts
是命名的导出,因此它的工作方式与此相反:

// This will work
import { storeProducts } from './data';
// This won't
import storeProducts from './data';

您可能使用大括号导入它,但对于
default
exports:

// This will work
import detailProduct from './data';

// This won't
import { detailProduct } from '.data';
另一方面,由于
storeProducts
是命名的导出,因此它的工作方式与此相反:

// This will work
import { storeProducts } from './data';
// This won't
import storeProducts from './data';

请发布尝试从此模块导入的代码。您可能希望使用
export const detailProduct={}
而不是
让detailProduct={},并删除默认导出。请参阅。您是否正确使用语法?请发布尝试从此模块导入的代码。您可能希望使用
export const detailProduct={}
而不是
让detailProduct={},并删除默认导出。请参阅。你使用的语法正确吗?哇。。。这就是一切。我几乎精神错乱了两个小时。谢谢你,尼克。这是我们中最好的!快乐编码哇。。。这就是一切。我几乎精神错乱了两个小时。谢谢你,尼克。这是我们中最好的!快乐编码