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>
<!--data-clipboard-text 值为要复制的文本内容 -->
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('复制失败');
});
},
}