Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useClipboardItems.md
1---2category: Browser3related:4- useClipboard5---67# useClipboardItems89Reactive [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API). Provides the ability to respond to clipboard commands (cut, copy, and paste) as well as to asynchronously read from and write to the system clipboard. Access to the contents of the clipboard is gated behind the [Permissions API](https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API). Without user permission, reading or altering the clipboard contents is not permitted.1011## Difference from `useClipboard`1213`useClipboard` is a "text-only" function, while `useClipboardItems` is a [ClipboardItem](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem) based function. You can use `useClipboardItems` to copy any content supported by [ClipboardItem](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem).1415## Usage1617```vue18<script setup lang="ts">19import { useClipboardItems } from '@vueuse/core'2021const mime = 'text/plain'22const source = ref([23new ClipboardItem({24[mime]: new Blob(['plain text'], { type: mime }),25})26])2728const { content, copy, copied, isSupported } = useClipboardItems({ source })29</script>3031<template>32<div v-if="isSupported">33<button @click="copy(source)">34<!-- by default, `copied` will be reset in 1.5s -->35<span v-if="!copied">Copy</span>36<span v-else>Copied!</span>37</button>38<p>39Current copied: <code>{{ content || 'none' }}</code>40</p>41</div>42<p v-else>43Your browser does not support Clipboard API44</p>45</template>46```4748## Type Declarations4950```ts51export interface UseClipboardItemsOptions<52Source,53> extends ConfigurableNavigator {54/**55* Enabled reading for clipboard56*57* @default false58*/59read?: boolean60/**61* Copy source62*/63source?: Source64/**65* Milliseconds to reset state of `copied` ref66*67* @default 150068*/69copiedDuring?: number70}71export interface UseClipboardItemsReturn<Optional> extends Supportable {72content: Readonly<Ref<ClipboardItems>>73copied: Readonly<ShallowRef<boolean>>74copy: Optional extends true75? (content?: ClipboardItems) => Promise<void>76: (text: ClipboardItems) => Promise<void>77read: () => void78}79/**80* Reactive Clipboard API.81*82* @see https://vueuse.org/useClipboardItems83* @param options84*85* @__NO_SIDE_EFFECTS__86*/87export declare function useClipboardItems(88options?: UseClipboardItemsOptions<undefined>,89): UseClipboardItemsReturn<false>90export declare function useClipboardItems(91options: UseClipboardItemsOptions<MaybeRefOrGetter<ClipboardItems>>,92): UseClipboardItemsReturn<true>93```94