<i
class="el-icon-document-copy copy-btn"
title="复制"
@click="handleCopyDDL(scoped.row)"
></i>
// 复制日志
handleCopyDDL (record) {
// record 需要复制的文字
// 创建input标签存放需要复制的文字
const oInput = document.createElement('textarea');
// 把文字放进input中,供复制
oInput.value = record;
document.body.appendChild(oInput);
// 选中创建的input
oInput.select();
// 执行复制方法, 该方法返回bool类型的结果,告诉我们是否复制成功
const copyResult = document.execCommand('copy');
// 操作中完成后 从Dom中删除创建的input
document.body.removeChild(oInput);
// 根据返回的复制结果 给用户不同的提示
if (copyResult) {
this.$message({
type: 'success',
message: '已复制到粘贴板'
});
} else {
this.$message({
type: 'warning',
message: '复制失败!'
});
}
},