useClipboard
Clipboard
stable
Headless clipboard composable. Wraps the modern navigator.clipboard.writeText API with a legacy execCommand fallback. Exposes a self-resetting copied flag so consumers do not need to wire the reset timeout themselves. Never throws — callers branch on the returned boolean.
API
Signature
Full TypeScript signature sourced from the composable file.
The timeout is cleared on Vue scope dispose (component unmount). No manual cleanup is required.
Consumed interfaces
IUseClipboardOptions
API
Parameters
Input parameters accepted by this composable.
- optionsIUseClipboardOptions{}
- Optional configuration object. Currently only feedbackDuration is supported.
- options.feedbackDurationnumber2000
- Duration in milliseconds the copied ref stays true after a successful write before auto-resetting.
API
Return values
Properties and methods exposed by the composable return object.
- copy
- Writes text to the clipboard. Returns true on success, false on failure. Resets the copied flag timer on each call.
- copied
- Reactive flag that is true for feedbackDuration ms after a successful copy, then automatically resets to false.
- error
- Set to the Error instance when the last copy attempt failed. Null after a successful copy or before any attempt.
- isSupported
- Whether the modern navigator.clipboard.writeText API is available. False in non-HTTPS contexts and older browsers — the execCommand fallback is still attempted in that case.
Usage
Examples
Ready-to-paste usage snippets.
Copy with automatic feedback
Check API support before copying