Vue项目下实现一键复制粘贴
kingcwt2023-10-09前端vue antd
实现一键复制粘贴
const onCopy = (id) => {
const ele = document.querySelector(`.className_${id}`)
if (window.getSelection) {
const selection = window.getSelection()
const range = document.createRange()
range.selectNodeContents(ele)
selection.removeAllRanges()
selection.addRange(range)
}
document.execCommand("copy")
message.success("已复制数据至剪贴板")
window.getSelection().removeAllRanges()
}