# Browser Compatibility
A, npm download
npm install clipboard --save
Second, the import component
import Clipboard from 'clipboard'
Third, the use
<button ref="copy" :data-clipboard-text="link" @click="copyLink">复制</button>
<script>
export default{
data () {
return {
link: 'https://clipboardjs.com/'
}
},
mounted () {
this.copyBtn = new Clipboard(this.$refs.copy)
},
copyLink () {
let clipboard = this.copyBtn
clipboard.on('success', function () {
console.log('成功')
})
clipboard.on('error', function () {
console.log('失败')
})
}
}
</script>
Fourth, the document
Used above is based on the operation of the Vue, if he is a native of the project, you can click on the link above to view the document