我正在尝试在用户单击按钮时弹出一个表单对话框。我几乎完全从Dialog Material-UI站点获取了如何使用一个按钮来完成此操作,该按钮将用于打开Dialog和在Dialog中添加的TextField。这是使用Meteor和React。当我在服务器上运行时,我收到一个错误。有人知道Missing class properties transform.
的含义吗?
代码
import React from 'react';
import Dialog from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton';
import FloatingActionButton from 'material-ui/FloatingActionButton';
import ContentAdd from 'material-ui/svg-icons/content/add';
import TextField from 'material-ui/TextField';
const style = {
marginRight: "20px",
position: "absolute",
left: "80%",
down: "80%",
};
export default class Events 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}
keyboardFocused={true}
onTouchTap={this.handleClose}
/>,
];
return (
<div>
<h1>Events</h1>
<FloatingActionButton style={style}>
<ContentAdd />
</FloatingActionButton>
<Dialog
title="Add Event"
actions={actions}
model={false}
open={this.state.open}
onRequestClose={this.handClose}
>
<TextField
hintText="Hint Text"
floatingLabelText="Floating Label Text"
/>
</Dialog>
</div>
);
}
}
错误
Errors prevented startup:
While processing files with ecmascript (for target web.browser):
client/events/Events.jsx:20:2: /client/events/Events.jsx: Missing class properties transform.
Your application has errors. Waiting for file change.
答案 0 :(得分:1)
请参阅我的其他答案以使此代码正常工作,但如果您愿意,也可以完全避免使用类语法。
import React from 'react';
import Dialog from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton';
import FloatingActionButton from 'material-ui/FloatingActionButton';
import ContentAdd from 'material-ui/svg-icons/content/add';
import TextField from 'material-ui/TextField';
const style = {
marginRight: "20px",
position: "absolute",
left: "80%",
down: "80%",
};
export default const Events = React.createClass({
getInitialState: function () {
return {
open: false
}
},
handleOpen: () => {
this.setState({open: true});
},
handleClose: () => {
this.setState({open: false});
},
render: function() {
const actions = [
<FlatButton
label="Cancel"
primary={true}
onTouchTap={this.handleClose}
/>,
<FlatButton
label="Submit"
primary={true}
keyboardFocused={true}
onTouchTap={this.handleClose}
/>,
];
return (
<div>
<h1>Events</h1>
<FloatingActionButton style={style}>
<ContentAdd />
</FloatingActionButton>
<Dialog
title="Add Event"
actions={actions}
model={false}
open={this.state.open}
onRequestClose={this.handClose}
>
<TextField
hintText="Hint Text"
floatingLabelText="Floating Label Text"
/>
</Dialog>
</div>
);
}
})
答案 1 :(得分:0)
假设您正在使用babel,则需要class properties转换。它包含在stage 2 preset中,如果更可取的话。你在使用webpack捆绑吗?共享您的webpack配置,尤其是js
中的jsx
/ loaders
部分会有所帮助。