gpt4 book ai didi

react-native - 我正在尝试导出此 JSON 数据以在项目中导入,但它显示意外的语法错误

转载 作者:行者123 更新时间:2023-12-04 17:46:47 25 4
gpt4 key购买 nike

当它与组件在同一个文件中时,它工作得很好。现在我试图将它从组件中排除,以使项目更清洁。但是它显示意外的语法错误。文件格式为 JSON。如何修复此代码并使其正常工作?

const postsData = [

{
id: 1,
title: "How to start a business with 100$",
published: "14h ago",
image: require("../img/img1.jpg"),
},
{
id: 2,
title: "Get funding for your startup",
published: "19h ago",
image: require("../img/img2.jpg"),
},
{
id: 3,
title: "Latest Fashion Trends for 2018",
published: "14h ago",
image: require("../img/img3.jpg"),
},

]

export {postsData};

最佳答案

试试这个:

export default [
{
id: 1,
title: "How to start a business with 100$",
published: "14h ago",
image: require("../img/img1.jpg"),
},
{
id: 2,
title: "Get funding for your startup",
published: "19h ago",
image: require("../img/img2.jpg"),
},
{
id: 3,
title: "Latest Fashion Trends for 2018",
published: "14h ago",
image: require("../img/img3.jpg"),
}
]

导入它就像

从“文件路径”导入 postsData;

附言:

  • postsData 没有命名规则,你可以自己命名任何东西。
  • 你的 json 文件应该有一个扩展名 .js 因为你没有使用 JSON 对象

关于react-native - 我正在尝试导出此 JSON 数据以在项目中导入,但它显示意外的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48110469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com