我有一个名为 style.js
的文件,其中包含以下内容:
const CenterStyle = {
width: 800,
backgroundColor: '#FFFFFF',
marginLeft: 300,
marginTop: 100
}
export { CenterStyle };
我有一个包含以下内容的 skills.js
文件:
import React, { Component } from 'react';
import { CenterSyle } from './style';
class Skills extend React.Component
.....React code......
然后最后在我的 App.js
文件中导入整个 Skills
类:
import Skills from './skills'
我遇到的问题是,在我的 skills.js
中,我的 CenterStyle
const 是 undefined
。它没有被导入。我做错了什么?
最佳答案
两件事
或者你可以尝试使用export before const as
export const CenterStyle = {
width: 800,
backgroundColor: '#FFFFFF',
marginLeft: 300,
marginTop: 100
}
并将其导入为
import { CenterSyle } from './style';
或
默认导出
const CenterStyle = {
width: 800,
backgroundColor: '#FFFFFF',
marginLeft: 300,
marginTop: 100
}
export default CenterStyle ;
并将其导入为
import CenterSyle from './style';
关于javascript - 为什么我的常量没有被导出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39910741/