Javascript 如何从reactJS中的另一个文件导入2,3对象
我是ReactJS的初学者,目前我正在为一些模块使用Javascript 如何从reactJS中的另一个文件导入2,3对象,javascript,reactjs,antd,ant-design-pro,Javascript,Reactjs,Antd,Ant Design Pro,我是ReactJS的初学者,目前我正在为一些模块使用样式化组件。实际上我在一个文件夹中创建了两个文件。一个是style.js我正在制作2,3对象,现在我想将这3个对象导出到我的另一个文件中,该文件名为2nd.js,但它对我不起作用。你能帮助我如何将style.js对象导入到我的文件中吗 Style.js代码 import styled from 'styled-components'; export const SubText = styled.div` font-size: 20
样式化组件
。实际上我在一个文件夹中创建了两个文件。一个是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;
`;
import Style from './Style';
<GeneralText>This is dummy text </GeneralText>
2nd.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;
`;
import Style from './Style';
<GeneralText>This is dummy text </GeneralText>
从“/Style”导入样式;
这是虚拟文本
您可以通过以下方式执行此操作:-
import {SubText, GeneralText, ButtonWrapper} from './style'
您可以通过以下方式完成此操作:-
import {SubText, GeneralText, ButtonWrapper} from './style'
实际上,有很多方法可以解决这个问题:
import * as Style from './style'
或者上面的答案是:
import {SubText, GeneralText, ButtonWrapper} from './style'
实际上,有很多方法可以解决这个问题:
import * as Style from './style'
或者上面的答案是:
import {SubText, GeneralText, ButtonWrapper} from './style'
您需要使用名称导入类似于{SubText,ButtonWrapper,GeneralText}@CodeManiac的东西,我已经尝试过了,但同时他们给了我错误
GeneralText未定义
@CodeManiac谢谢您解决:)您需要使用名称导入类似以下内容{SubText,ButtonWrapper,GeneralText}@CodeManiac我已经尝试过了,但同时他们给我错误<代码>GeneralText未定义@CodeManiac谢谢解决:)