One, operation Dom implementation

The formulation text is shown below, and the antDesign component library is used for development

<p id='onregCopyClose'> This is the text to copy </p>Copy the code

Write a button

<Button onClick={this.copywrite ()}>Copy the code

The binding click event code is shown below

onregCopyClose = () => {
    const copyD = document.getElementById("copyTxt"); const range = document.createRange() window.getSelection().removeAllRanges(); // Clear the cursor selection range.selectNode(copyD); // Select the Dom node and its descendants window.getSelection().addrange (range); // add range const copySuccess = document. ExecCommand ('copy'); // Copy the current selection to the clipboardif(copySuccess) {
      window.getSelection().removeAllRanges();
      this.setState({ regVisible: false})}else {
      Message.error("Copy failed, please copy again"); }}Copy the code

The syntax for the createRange method is shown below, and the return value is a range object with both boundary points set to the beginning of the document.

createRange()
Copy the code

2. Pure virtual Dom implementation

Haven’t worked out how to do that yet… To research and development of