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
Signature TypeScript complète extraite du fichier du composable.
The timeout is cleared on Vue scope dispose (component unmount). No manual cleanup is required.
Interfaces consommées
IUseClipboardOptions
API
Paramètres
Paramètres d'entrée acceptés par ce 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
Valeurs de retour
Propriétés et méthodes exposées par l'objet retourné par le composable.
- 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
Exemples
Extraits de code prêts à coller.
Copy with automatic feedback
Check API support before copying