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 })
    }
}

---

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2021-12-10
  • 2021-10-07
猜你喜欢
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2021-09-06
  • 2021-08-01
  • 2022-12-23
  • 2022-01-04
相关资源
相似解决方案