clipboard.js 546 B

12345678910111213141516171819202122232425262728
  1. import Vue from 'vue'
  2. import {write} from 'clipboardy/browser'
  3. function clipboardSuccess() {
  4. Vue.prototype.$message({
  5. message: 'Copy successfully',
  6. type: 'success',
  7. duration: 1500
  8. })
  9. }
  10. function clipboardError() {
  11. Vue.prototype.$message({
  12. message: 'Copy failed',
  13. type: 'error'
  14. })
  15. }
  16. export default function handleClipboard(text, event) {
  17. /*const clipboard = new Clipboard(event.target, {
  18. text: () => text
  19. })*/
  20. write(text).then(res => {
  21. clipboardSuccess()
  22. }).catch(err => {
  23. clipboardError()
  24. })
  25. }