clipboard.js 705 B

12345678910111213141516171819202122232425262728293031
  1. import Vue from 'vue'
  2. import Clipboard from 'clipboard'
  3. function clipboardSuccess() {
  4. Vue.prototype.$baseMessage('复制成功', 'success')
  5. }
  6. function clipboardError() {
  7. Vue.prototype.$baseMessage('复制失败', 'error')
  8. }
  9. /**
  10. * @author https://vue-admin-beautiful.com (不想保留author可删除)
  11. * @description 复制数据
  12. * @param text
  13. * @param event
  14. */
  15. export default function handleClipboard(text, event) {
  16. const clipboard = new Clipboard(event.target, {
  17. text: () => text,
  18. })
  19. clipboard.on('success', () => {
  20. clipboardSuccess()
  21. clipboard.destroy()
  22. })
  23. clipboard.on('error', () => {
  24. clipboardError()
  25. clipboard.destroy()
  26. })
  27. clipboard.onClick(event)
  28. }