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()
}
Last Updated 10/16/2023, 7:06:22 AM
What do you think?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
Comments
  • Latest
  • Oldest
  • Hottest
Powered by Waline v2.15.8