useCopy.ts 443 B

1234567891011121314151617181920
  1. import { ElMessage } from 'element-plus'
  2. /**
  3. * 复制内容到剪贴板
  4. * @param {string} content 要复制的内容
  5. * @example
  6. * getCopy('这是测试文字')
  7. */
  8. export function useCopy(content: string) {
  9. try {
  10. navigator.clipboard.writeText(content) // 把要复制的内容拷贝到剪贴板
  11. ElMessage({
  12. message: '复制成功',
  13. type: 'success',
  14. plain: true,
  15. })
  16. }
  17. catch (ex) {
  18. return false
  19. }
  20. }