docs(examples): use useClipboard instead of navigator.clipboard

This commit is contained in:
Benjamin Canac
2025-06-18 14:16:54 +02:00
parent abfd0ede03
commit 04f12adc5b
5 changed files with 17 additions and 14 deletions

View File

@@ -1,15 +1,9 @@
<script setup lang="ts">
import { useClipboard } from '@vueuse/core'
const value = ref('npx nuxt module add ui')
const copied = ref(false)
function copy() {
navigator.clipboard.writeText(value.value)
copied.value = true
setTimeout(() => {
copied.value = false
}, 2000)
}
const { copy, copied } = useClipboard()
</script>
<template>
@@ -25,7 +19,7 @@ function copy() {
size="sm"
:icon="copied ? 'i-lucide-copy-check' : 'i-lucide-copy'"
aria-label="Copy to clipboard"
@click="copy"
@click="copy(value)"
/>
</UTooltip>
</template>