如何从 reactJS 中的另一个文件导入 2,3 对象

How to import 2,3 object from another file in reactJS

我是 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>

您可以通过以下方式完成此操作:-

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

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

import * as Style from './style'

或者上面的回答说:

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