(text: string)
| 11 | const error = ref<Error | null>(null); |
| 12 | |
| 13 | async function copy(text: string): Promise<boolean> { |
| 14 | if (!isSupported.value) { |
| 15 | error.value = new Error("Clipboard API not supported"); |
| 16 | return false; |
| 17 | } |
| 18 | |
| 19 | try { |
| 20 | await navigator.clipboard.writeText(text); |
| 21 | copied.value = true; |
| 22 | error.value = null; |
| 23 | |
| 24 | // 2秒后重置状态 |
| 25 | setTimeout(() => { |
| 26 | copied.value = false; |
| 27 | }, 2000); |
| 28 | |
| 29 | return true; |
| 30 | } catch (err) { |
| 31 | error.value = err as Error; |
| 32 | copied.value = false; |
| 33 | return false; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | async function read(): Promise<string | null> { |
| 38 | if (!isSupported.value) { |
no outgoing calls
no test coverage detected