【Ant Design】-button 添加文本复制功能

1. 添加button按钮

<a-button type="primary" size="small" @click="onCopy(viewDetailForm.val)">复制</a-button>

2. method中添加copy方法

onCopy(certB64){
  let oInput = document.createElement('input')
  oInput.value = certB64;
  document.body.appendChild(oInput)
  oInput.select() // 选择对象
  document.execCommand("Copy") // 执行浏览器复制命令
  this.$message.success("复制成功");
  oInput.remove()
}

以上代码,支持Element-UI,Ant Design两种前端UI框架。

原文地址:https://www.cnblogs.com/juihai/p/13717445.html