We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
创建BraftEditor.tsx子组件:
import BraftEditor, { EditorState } from 'braft-editor' import NoSSR from 'components/NoSSR' import React from 'react' export default class Child extends React.Component { state = { // 创建一个空的editorState作为初始值 editorState: BraftEditor.createEditorState(null) } async componentDidMount () { // 假设此处从服务端获取html格式的编辑器内容 const htmlContent = "<div><b>123</b></div>" // 使用BraftEditor.createEditorState将html字符串转换为编辑器需要的editorStat this.setState({ editorState: BraftEditor.createEditorState(htmlContent) }) } submitContent = async () => { // 在编辑器获得焦点时按下ctrl+s会执行此方法 // 编辑器内容提交到服务端之前,可直接调用editorState.toHTML()来获取HTML格式的内容 const htmlContent = this.state.editorState.toHTML() console.log(htmlContent); } handleEditorChange = (editorState: EditorState) => { this.setState({ editorState }) } render () { const { editorState } = this.state return ( <div className="my-component"> <BraftEditor value={editorState} onChange={this.handleEditorChange} onSave={this.submitContent} /> </div> ) } }
父组件引用:
import React from 'react' import dynamic from 'next/dynamic' import 'braft-editor/dist/index.css' const BraftEditor = dynamic(() => import('./BraftEditor'), { ssr: false }) export default function EditorDemo() { return <BraftEditor /> }
开发模式下没问题可以正常使用富文本,但是执行yarn build报错: ReferenceError: window is not defined
yarn build
ReferenceError: window is not defined
The text was updated successfully, but these errors were encountered:
这个问题我解决了 https://blog.csdn.net/mengdasheng/article/details/113726981
Sorry, something went wrong.
No branches or pull requests
创建BraftEditor.tsx子组件:
父组件引用:
开发模式下没问题可以正常使用富文本,但是执行
yarn build
报错:ReferenceError: window is not defined
The text was updated successfully, but these errors were encountered: