Use clipboard plugin (browser copy and paste function)

# Browser Compatibility

Minimum supported version of the standard browser

 

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

https://clipboardjs.com/


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

Guess you like

Origin blog.csdn.net/WANG_CA/article/details/90020171