copy-button.vue 819 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <template>
  2. <i class="el-icon-copy-document tag-read" v-if="copyText" @click="copy(copyText)" :data-clipboard-text="copyText">
  3. </i>
  4. </template>
  5. <script>
  6. import Clipboard from 'clipboard'
  7. export default {
  8. name: 'CopyButton',
  9. props: {
  10. copyText: {
  11. // 复制文本
  12. type: String,
  13. default: ''
  14. }
  15. },
  16. data() {
  17. return {}
  18. },
  19. methods: {
  20. copy() {
  21. const clipboard = new Clipboard('.tag-read')
  22. // clipboard.on('success', e => {
  23. // this.$successMsg('复制成功');
  24. // })
  25. clipboard.on('error', e => {
  26. console.log('该浏览器不支持复制')
  27. return false
  28. })
  29. this.$successMsg('复制成功')
  30. }
  31. }
  32. }
  33. </script>
  34. <style lang="scss" scoped>
  35. .tag-read {
  36. color: #409eff;
  37. cursor: pointer;
  38. margin-right: 4px;
  39. }
  40. </style>