私はreactjsに新しく、私はantdのモーダル機能を使用しようとしています。しかし、基本的なサンプルコードを自分のコードベースに組み込むと、いくつかのエラーが残っています。コロンと末尾のカンマを削除しなければならず、状態変数にエラーが発生します。Reactjsとantd modals - コードの問題
https://ant.design/components/modal/
import { Modal, Button } from 'antd';
class App extends React.Component {
state = { visible: false }
showModal =() => {
this.setState({
visible: true,
});
}
handleOk = (e) => {
console.log(e);
this.setState({
visible: false,
});
}
handleCancel = (e) => {
console.log(e);
this.setState({
visible: false,
});
}
render() {
return (
<div>
<Button type="primary" onClick={this.showModal}>Open</Button>
<Modal
title="Basic Modal"
visible={this.state.visible}
onOk={this.handleOk}
onCancel={this.handleCancel}
>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</Modal>
</div>
);
}
}
ReactDOM.render(<App />, mountNode);
私のエラーは、構文エラーのですか?私はコンストラクタで状態を設定しようとしましたが、それは未定義です。
client:119 ./src/components/Video/VideoConference.js
Module build failed: SyntaxError: D:/wamp/www/e-profound-react/src/components/Video/VideoConference.js: Unexpected token (631:8)
629 | }
630 |
> 631 | state = { visible: false }
| ^
632 | showModal() {
633 | this.setState({
634 | visible: true,
@ ./src/router.js 35:0-65
@ ./src/index.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./index.js
私のコードはもっと複雑に見えますが、このように見えます。
class VideoConference extends React.Component {
constructor (props) {
super(props)
}
componentWillMount() {
}
componentWillUnmount() {
}
componentDidMount() {
}
state = { visible: false }
showModal() {
this.setState({
visible: true,
})
}
handleOk (e) {
console.log(e)
this.setState({
visible: false,
})
}
handleCancel (e) {
console.log(e)
this.setState({
visible: false,
})
}
render() {
return (
<div>
<Spacers />
<Button type='primary' onClick={this.showModal}>Open</Button>
<Modal
title='Basic Modal'
visible={this.state.visible}
onOk={this.handleOk}
onCancel={this.handleCancel}
>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</Modal>
</div>
)
}
}
これまでのところ良いです。 Tks:D。 –
- このメソッドをバベルローダーのこの部分に配置しますか? –
私のバベルローダーは基本的に見えますか? - { :resolve( 'src')、 テスト:/ \。js $ /、 ローダー: 'babel-loader'、 除外: '/ node_modules' }、 –