npm模块copy-to-clipboard复制内容到剪切板
Posted xy-ouyang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 type="primary" 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 }) } }
---
以上是关于npm模块copy-to-clipboard复制内容到剪切板的主要内容,如果未能解决你的问题,请参考以下文章