npm模块copy-to-clipboard复制内容到剪切板
import React from 'react' import copy from 'copy-to-clipboard' export default class App extends React.Component { constructor(props) { super(props) this.state = { content: '' } } render() { const { content } = this.state return ( <div> <button onClick={this.copyToClipboard}>点击复制输入框内容</button> <input type='text' value={content} onChange={this.inputChangeHandler} ref={input => this.myInput = input} /> </div> ) } copyToClipboard = () => { // Get the value of the `value` attribute of the <Input> component // copy(this.myInput.value) copy(this.state.content) } inputChangeHandler = e => { console.log(`e.target.value=${e.target.value}`) console.log(`this.myInput.value=${this.myInput.value}`) this.setState({ content: e.target.value }) } }
---
posted on 2020-01-18 14:05 wenbin_ouyang 阅读(3232) 评论(0) 编辑 收藏 举报