How to click the @ click event in vue to copy some data from data to the clipboard

as the title, @ click event, to get some data data, you need to put this content in the clipboard.

Feb.28,2021

you can put your data into a hidden input element, select it and copy it.

<input id="copyme" value="your data">
$('-sharpcopyme').select();
document.execCommand('copy');

I wrote an article: Vue with clipboard.js to click the button to copy the content to the clipboard

< hr >

I hope it will be helpful to you!


give you a copy method written by myself, just pass in what you want to copy and determine whether it is on the clipboard by returning the result.

function copyText (text) {
  let copyInput = document.createElement('INPUT')
  copyInput.type = 'text'
  copyInput.style.width = '1px'
  copyInput.style.height = '1px'
  copyInput.style.border = 0
  copyInput.style.outline = 0
  document.body.appendChild(copyInput)
  copyInput.value = text
  copyInput.select()
  const result = document.execCommand('Copy')
  document.body.removeChild(copyInput)
  return result
}
Menu