我正在使用React Draft Wysiwyg,我需要将应用程序的一个组件中的任意文本插入到编辑器组件中。我通过剪贴板作为从一个组件传输到另一个组件的中介来执行此操作。但是document.execCommand('paste')失败了。
有人知道怎么做这个吗?
我的示例代码在这里;第三个控制台日志为粘贴结果发出 false。
import React, { Component } from 'react';
import { EditorState, convertToRaw, Modifier } from 'draft-js';
import { Editor } from 'react-draft-wysiwyg';
import draftToHtml from 'draftjs-to-html';
import htmlToDraft from 'html-to-draftjs';
import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css';
import styled from 'styled-components';
class EditorConvertToHTML extends Component {
constructor(props) {
super(props);
this.state = {editorState: EditorState.createEmpty()};
this.onChange = (editorState) => this.setState({editorState});
this.setEditor = (editor) => {
this.editor = editor;
};
this.focusEditor = () => {
if (this.editor) {
this.editor.focusEditor(); …Run Code Online (Sandbox Code Playgroud) javascript reactjs draftjs draft-js-plugins react-draft-wysiwyg