The plug-in package using the clipboard-polyfill
1 import React, { Component } from 'react' 2 3 import clipboard from "clipboard-polyfill" 4 import {Button} from "antd" 5 6 export default class Main extends Component { 7 constructor(props){ 8 super(props); 9 this.state={ 10 opj:{ 11 "param.code.name":"姓名", 12 "param.codexname":"昵称", 13 "param.code.age":"年龄", "param.code.gender": "Sex"14, 15 "param.code.hobby": "hobby" , 16 }, 17 Val: "Hello everyone this is the new student, called, can also be called this year, and like, like" , 18 changeVal: "" . 19 } 20 is } 21 is the render () { 22 is // the console.log (Object.entries (this.state)) 23 is return ( 24 <div> 25 <className = div "Top"> 26 is {Object.entries ( the this .STATE .opj) .map ((Item, index) => { 27 return <Button className="btn" key={index} onClick={this.copy.bind(this,index,item)}>{item[1]}</Button> 28 })} 29 </div> 30 <textarea name="" id="text" ref="text" onPaste={this.paste.bind(this)} cols="30" rows="10" value={this.state.val} onChange={(e)=>{ 31 this.setState({ 32 val:e.target.value 33 }) 34 }} /> 35 <button onClick={this.del.bind ( the this )}> removal value </ Button> 36 <Button the onClick = { the this .add.bind ( the this )}> complement value </ Button> 37 [ </ div> 38 is ) 39 } 40 Copy (index , Item) { 41 is // document.execCommand ( "the copy"); // copy command executing a browser 42 is // the let BTN = document.querySelectorAll ( "BTN.") [index] 43 is // btn.value = `[ Item {$ [. 1]} ({$ Item [0]})] ` 44 is // btn.select () 45 // the console.log (document.execCommand (" the Copy ")) 46 is // BTN.value=item[1] 47 48 the let text = `[Item {$ [. 1]} ({$ Item [0 ]})]`; 49 // Copy text to the clipboard 50 clipboard.writeText (text) 51 is // the console.log (text ); 52 is } 53 is del () { 54 is the let STR = the this .state.val; 55 STR str.replace = ( "]", "" ) 56 is .? the let RES = / \ [* \ (/ G; 57 is STR str.replace = (RES, "(" ) 58 // the console.log (STR); 59 the this .setState ({ 60 Val: STR 61 is }) 62 } 63 add(){ 64 let str=this.state.val; 65 if(str.indexOf("]")<0){ 66 console.log(111) 67 str=str.replace(/\((.+?)\)/g, ($0,$1,$2)=> { 68 console.log($0,$1,$2,"============"); 69 return `[${this.state.opj[$1]}${$0}]` 70 }); 71 console.log(str) 72 this.setState({ 73 Val: STR 74 }) 75 } 76 77 } 78 // paste time-triggered 79 Paste () { 80 // -------- 81 the this .setState ({ 82 changeVal: the this .state.val 83 } ) 84 85 } 86 }