-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
App.js
48 lines (44 loc) · 1.17 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import E from 'wangeditor'
class App extends Component {
constructor(props, context) {
super(props, context);
this.state = {
editorContent: ''
}
}
render() {
return (
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h2>Welcome to React</h2>
</div>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
{/* 将生成编辑器 */}
<div ref="editorElem" style={{textAlign: 'left'}}>
</div>
<button onClick={this.clickHandle.bind(this)}>获取内容</button>
</div>
);
}
componentDidMount() {
const elem = this.refs.editorElem
const editor = new E(elem)
// 使用 onchange 函数监听内容的变化,并实时更新到 state 中
editor.customConfig.onchange = html => {
this.setState({
editorContent: html
})
}
editor.create()
}
clickHandle() {
alert(this.state.editorContent)
}
}
export default App;