vue中使用clipboard.js复制指定内容到剪贴板

关键词:clipboard.js; vue;
从npm安装

npm install clipboard --save

html


js

import Clipboard from 'clipboard'
export default{
  data() {
    return {
      shareText: ''
    }
  },
  methods: {
    handleShareClick(){
      const clipboard = new Clipboard('.share');
      this.shareText= 'hhh'
      clipboard.on('success', e => {
        this.$message.success('分享内容复制成功');
        clipboard.destroy();
      });
      clipboard.on('error', e => {
        this.$message.error('分享内容复制失败');
        clipboard.destroy();
      });
    }
  }
}

参考链接
https://segmentfault.com/a/1190000020651289?utm_source=tag-newest

你可能感兴趣的:(vue中使用clipboard.js复制指定内容到剪贴板)