【发布时间】:2016-12-24 09:16:09
【问题描述】:
所以我刚刚尝试获取 google 材料对话框。 我对流星很陌生,所以对你来说答案可能比对我更明显。
即便如此,我的控制台还是给了我这个错误:
Missing class properties
transform.
在这个文件的第 16 行:
export default class DialogExampleCustomWidth extends React.Component {
state = {
open: false,
};
handleOpen = () => {
this.setState({open: true});
};
handleClose = () => {
this.setState({open: false});
};
render() {
const actions = [
<FlatButton
label="Cancel"
primary={true}
onTouchTap={this.handleClose}
/>,
<FlatButton
label="Submit"
primary={true}
onTouchTap={this.handleClose}
/>,
];
return (
<div>
<RaisedButton label="Dialog With Custom Width" onTouchTap={this.handleOpen} />
<Dialog
title="Dialog With Custom Width"
actions={actions}
modal={true}
contentStyle={customContentStyle}
open={this.state.open}
>
This dialog spans the entire width of the screen.
</Dialog>
</div>
);
}
}
错误出现在state = {
我已经阅读了多篇文章,但似乎无法理解。感谢您的帮助和时间
【问题讨论】:
-
实例属性在 JS 中没有标准化。您需要在构造函数中初始化您的状态。
constructor() { this.state = ... } -
它说在超级 @zerkms 之前不允许使用 'this'
-
所以 - 打电话给
super()? -
对于其他发现此问题并使用 SublimeText 的人。由于@henk 的回答解决了这个问题,然后我跟着Dan Abramov's blog post 修复了SublimeText 中的ESLint / Babel linting - 否则只会在
state = {行抛出一个错误并且没有进一步。