e是传递的数据 就是需要复制的文本
渲染表格的时候:
{
dataIndex: 'modelPath',
key: 'modelPath',
title: 'name',
render(_, item) {
return (
<div className="modeHtml">
<Popover content={item.modelPath}>
<div className="modePathTitle">{item.modelPath}</div>
</Popover>
<CopyOutlined
onClick={() => {
copyList(item)
}}
/>
</div>
)
}
},
点击复制按钮 复制需要的item
const copyList = e => {
const textToCopy = e.modelPath
// 创建一个虚拟input元素
const input = document.createElement('input')
input.value = textToCopy
document.body.appendChild(input)
// 选择输入框的内容
input.select()
input.setSelectionRange(0, 99999) // 兼容移动设备
// 执行复制操作
document.execCommand('copy')
// 移除虚拟input元素
document.body.removeChild(input)
// 可以显示一条消息或者执行其他操作
alert('已复制到剪贴板!')
}