Vue中点击复制文本功能

1.下载clipboard.js

npm install clipboard --save

2.引入插件

//main.js中全局引入
import clipboard from 'clipboard';
Vue.prototype.clipboard = clipboard

3.代码编写

 <a @click="copy" :data-clipboard-text="record.wenjuanLink" id="express_info_right">复制链接a>
 
methods:{
     
  copy(){
     
      let clipboard = new this.clipboard("#express_info_right");
      let that = this
      clipboard.on('success', function () {
     
        that.$message.success('复制成功');
        clipboard.destroy();
      });
      clipboard.on('error', function () {
     
        that.$message.error('复制失败');
      });
    },
}

你可能感兴趣的:(vue,js,vue,js)