arrays - 如何在许多 const react 中存储和导出对象数量
问题描述
我是 React 的新手,在每个组件中我都初始化了我渲染组件的对象
在所有组件对象都被初始化后,我想将所有的整个对象存储在一个文件中。如何存储和导出具有不同变量的所有对象
这是我的示例代码
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
class Footer extends Component {
render() {
const links = {
classname: ["fa-phone", "fa-envelope","fa-location-arrow"],
content: ["Tel:", "Email:","Location:"],
};
return (
<div>
<ul>
{links.classname.map((name, i) =>
<li style={{ listStyleType:"none" }} key={name}> <i className={`fa ${name} text-primary`}></i> <b className="p-lr5">{links.content[i]}</b>{links.subcontent[i]}</li>
)}
</ul>
</div>
);
}
}
export default Footer;
我尝试这样做如何将对象集合保存在一个文件中
const links1 = {
classname: ["fa-phone", "fa-envelope", "fa-location-arrow"],
content: ["Tel:", "Email:", "Location:"],
subcontent: ["04324-263537", "karurknv@gmail.com", "239, Jawahar Bazaar, karur - 639001"],
};
const links2 = {
links: ["Home", "About Us", "Products", "Gallery", "Services"],
to: ["/", "aboutus", "/products", "/gallery", "/services", "/contact"],
};
const links3 = {
links2: ["/terms&condition", "/privatepolicy", "/contact"],
to2: ["Terms & Condition", "Privacy Policy", "Contact Us"]
};
请帮我
解决方案
使用export
而不是export default
. 喜欢export const MyComponent
。
推荐阅读
- pyinstaller - pyinstaller - 如何获取随机生成的临时文件夹的名称?
- c# - .NET Core 3 与 MVC Razor - 更改日期格式
- express - 带有快速车把的 webpack
- sharepoint - 共享点列表:如果在 A 列中具有相同的值,则不允许 B 列中的重复值
- winforms - WinForms:如果添加带有“已更改”后缀的事件,为什么数据绑定会中断?
- json - 多线程 Json.NET 序列化中的性能
- c# - Visual Studio:将本地主机上运行的 MySQL 数据库连接到 ASP.NET 项目
- javascript - 如何根据选中的复选框读取输入值?
- django - Django - 使用外键从第三个模型中获取对象
- algorithm - 拆分数字数组的最有效方法是什么,以使每个子集的总和尽可能接近目标而不超过目标?