【问题标题】:How to store and export number of object in many const react如何在许多 const react 中存储和导出对象数量
【发布时间】:2019-01-20 16:05:58
【问题描述】:

我是 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"]
};

请帮帮我

【问题讨论】:

    标签: arrays reactjs react-redux


    【解决方案1】:

    使用export 代替export default。喜欢export const MyComponent

    【讨论】:

      猜你喜欢
      • 2013-11-19
      • 2018-09-11
      • 1970-01-01
      • 2019-02-16
      • 1970-01-01
      • 2020-02-18
      • 1970-01-01
      • 2016-06-16
      • 1970-01-01
      相关资源
      最近更新 更多