【问题标题】:How to import 2,3 object from another file in reactJS如何从 reactJS 中的另一个文件导入 2,3 对象
【发布时间】:2019-05-13 12:38:32
【问题描述】:

我是 ReactJS 的初学者,目前我正在使用 styled-component 来设置某些模块的样式。实际上我在一个文件夹中创建了 2 个文件。一个是 style.js 我正在制作 2,3 对象,现在我想将这 3 个对象导出到我的另一个文件,名称为 2nd.js 但它对我不起作用,请你帮我如何导入 style.js反对我的文件。

Style.js 代码

  import styled from 'styled-components';

  export const SubText = styled.div`
  font-size: 20px;
  text-align: center;
  padding-bottom: 30px;
  width: 330px;
  color: #012653;
  margin: 0 auto;
  font-weight: 440;
`;
export const GeneralText = styled.div`
  color: red;
  font-size: 26px;
  font-weight: 600;
  text-align: center;
  min-width: 266px;
  padding-bottom: 30px;
  font-family: Lato, sans-serif;
  margin-top: 50px;
  color: #012653;
`;
export const ButtonWrapper = styled.div`
  text-align: center;
  margin-top: 26px;
`;

2nd.js 代码

    import Style from './Style';

<GeneralText>This is dummy text </GeneralText>

【问题讨论】:

  • 你需要使用类似这样的名称导入 {SubText,ButtonWrapper, GeneralText }
  • @CodeManiac 我已经尝试过,但与此同时他们给了我错误...GeneralText is not defined
  • @CodeManiac 谢谢你解决了:)

标签: javascript reactjs antd ant-design-pro


【解决方案1】:

你可以这样做:-

import {SubText, GeneralText, ButtonWrapper} from './style'

【讨论】:

    【解决方案2】:

    其实解决这个问题的方法有很多:

    import * as Style from './style'
    

    或者上面的答案说:

    import {SubText, GeneralText, ButtonWrapper} from './style'
    

    【讨论】:

      猜你喜欢
      • 2021-11-19
      • 1970-01-01
      • 1970-01-01
      • 2021-04-18
      • 2017-10-23
      • 2021-03-21
      • 2022-01-03
      • 1970-01-01
      • 2021-03-07
      相关资源
      最近更新 更多