我创建了一个只显示block[0]值的组件,它不显示整个块值。
例如,如果我写:
HI
Stackoverflow
它只显示"Hi",不显示该字段的全部内容。
任何人都可以帮助我获取我在该输入字段中写入的全部数据吗?
import React from "react";
import { Editor } from "react-draft-wysiwyg";
import "react-draft-wysiwyg/dist/react-draft-wysiwyg.css";
export default class Edit extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
render() {
return (
<div>
<Editor value={this.props.value} onChange={this.props.onChange} />
</div>
);
}
}
应用组件:
import React from "react";
import Body from "./Body";
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
body: ""
};
}
changeBodyHandler = value => {
console.log(value.blocks[0].text);
this.setState({
body: value.blocks[0].text
});
};
render() {
return (
<div>
<Body
label="Body"
name="body"
value={this.state.body}
onChange={this.changeBodyHandler}
/>
</div>
);
}
}
export default App;
这是整个代码:
“ https://codesandbox.io/s/compassionate-tereshkova-89fm2 ”
萧十郎
慕工程0101907
相关分类