utils.js 496 B

12345678910111213141516171819202122
  1. import Clipboard from 'clipboard'
  2. export function handleClipboard (text, event, onSuccess, onError) {
  3. event = event || {}
  4. const clipboard = new Clipboard(event.target, {
  5. text: () => text
  6. })
  7. clipboard.on('success', () => {
  8. onSuccess()
  9. clipboard.off('error')
  10. clipboard.off('success')
  11. clipboard.destroy()
  12. })
  13. clipboard.on('error', () => {
  14. onError()
  15. clipboard.off('error')
  16. clipboard.off('success')
  17. clipboard.destroy()
  18. })
  19. clipboard.onClick(event)
  20. }