Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

求助:toHTML 得到空的内容 #633

Open
dmwin72015 opened this issue Oct 11, 2019 · 6 comments
Open

求助:toHTML 得到空的内容 #633

dmwin72015 opened this issue Oct 11, 2019 · 6 comments

Comments

@dmwin72015
Copy link

dmwin72015 commented Oct 11, 2019

直接copy示例代码

// 引入编辑器组件
import BraftEditor from 'braft-editor'
// 引入编辑器样式
import 'braft-editor/dist/index.css'
import { Card, Button } from 'antd'

export default class EditorDemo extends React.Component {

  state = {
    // 创建一个空的editorState作为初始值
    editorState: BraftEditor.createEditorState(null)
  }

  componentDidMount() {
    // 假设此处从服务端获取html格式的编辑器内容
    // const htmlContent = await fetchEditorContent()
    // 使用BraftEditor.createEditorState将html字符串转换为编辑器需要的editorStat
    // this.setState({
    //   editorState: BraftEditor.createEditorState(null)
    // })
  }

  submitContent = async () => {
    // 在编辑器获得焦点时按下ctrl+s会执行此方法
    // 编辑器内容提交到服务端之前,可直接调用editorState.toHTML()来获取HTML格式的内容
    // const htmlContent = this.state.editorState.toHTML()
    // const result = await saveEditorContent(htmlContent)
  }

  handleEditorChange = (editorState: any) => {
    this.setState({ editorState })
  }

  handleSubmit = () => {
    const { editorState } = this.state

    console.log('???', editorState.toHTML())
    console.log('???', editorState.toText())
  }

  render() {
    const { editorState } = this.state
    return (
      <Card className="my-component">
        <BraftEditor
          value={editorState}
          onChange={this.handleEditorChange}
          onSave={this.submitContent}
        />
        <p>
          <Button onClick={this.handleSubmit}>提交</Button>
        </p>
      </Card>
    )
  }
}

结果:
image

@Dongfengjie
Copy link

老铁你的解决没,我的也存在这个问题。。 toRAW()的话就没任何事。。。

@drxiao1
Copy link

drxiao1 commented Dec 2, 2019

同问

@dmwin72015
Copy link
Author

老铁你的解决没,我的也存在这个问题。。 toRAW()的话就没任何事。。。

没有放弃使用了

@yoxe
Copy link

yoxe commented Sep 8, 2020

我也遇到了同样的问题,删掉所有依赖重新装了一遍,就ok了,我不知道是玄学还是怎样。不过可以试试这种方式

@Prottoy2938
Copy link

Prottoy2938 commented Nov 12, 2020

@yoxe , can you share your package.json?

Maybe it has something do with the package version.

I'm facing the same issue.

@tonyyxliu
Copy link

I had the same problem. For me, the reason seemed to be that I npm install draft-js apart from this braft-editor. After executing npm uninstall draft-js, things becomes good. Please have a check. Hope this works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants