作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我有一个 JavaScript 文件(lib.js),它导出一些类、函数等。
export class Employment {
id = "";
startDate = "";
endDate = "";
companyEmailAddress = "";
};
export function HolidayPopupContainer() {
return (<div id="#HolidayPopupContainer" />);
}
export default withStyles(styles)(Button);
export default class DayView extends React.Component {
constructor(props) {
super(props);
this.state = {
readOnly: false
}
};
export const Status = [
"Select Status",
"Pending",
"Approved",
"Rejected",
"All"
]
Employment
HolidayPopupContainer
withStyles
DayView
Status
最佳答案
首先,一个模块中应该只有一个默认导出。如果您解决了这个问题,并删除了默认导出之一 - 比如说,您更改了 DayView
到一个命名的导出,然后用
import * as LibNamespace from './lib.js'
default
默认导出的属性。对于您的代码,此对象的键将是
console.log(Object.keys(LibNamespace))
// ['Employment', 'HolidayPopupContainer', 'default', 'DayView', 'Status']
withStyles
被“命名”,并包含在上面而不是
default
,您需要将其更改为命名导出:
const exportedVar = withStyles(styles)(Button);
export { exportedVar as withStyles };
withStyles
的变量。在范围内。也许将导出的变量称为其他变量:
export const buttonResult = withStyles(styles)(Button);
关于javascript - 有没有办法从 JavaScript 文件中获取所有导出的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59175280/
我是一名优秀的程序员,十分优秀!