做富文本编辑的时候会遇到一个问题,图片选择后立马上传到服务器的话,用户如果最后没有发表文章,就会导致服务器有很多垃圾的图片,我这里的处理是:从本地选择之后不上传服务器,直接把图片转换成base64 本地预览。下面是代码:
这个是UI的代码
const textEditor = (
<Editor
editorState={editorState}
toolbarClassName="home-toolbar"
wrapperClassName="home-wrapper"
editorClassName="home-editor"
onEditorStateChange={this.onEditorStateChange}
toolbar={
{
history: { inDropdown: true },
inline: { inDropdown: false },
list: { inDropdown: true },
textAlign: { inDropdown: true },
image: {
urlEnabled: false,
uploadEnabled: true,
alignmentEnabled: true, // 是否显示排列按钮 相当于text-align
uploadCallback: this.imageUploadCallBack,
previewImage: true,
inputAccept: 'image/*