我有一个名为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。不是进口的。我做错什么了?
发布于 2016-10-07 06:48:40
两件事
您可以尝试在const之前使用导出作为
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';发布于 2016-10-07 06:45:54
这应该能起作用:
export const CenterStyle = {
width: 800,
backgroundColor: '#FFFFFF',
marginLeft: 300,
marginTop: 100
}然后在你的技能中将其导入如下:
import { CenterSyle } from './style';https://stackoverflow.com/questions/39910741
复制相似问题