feat(clipboard): replace navigator.clipboard with vueuse useClipboard (#33)

This commit is contained in:
Sylvain Marroufin
2022-02-17 17:48:13 +01:00
committed by GitHub
parent e1d79d7fe7
commit 4532e09ac0
2 changed files with 8 additions and 9 deletions

View File

@@ -1,13 +1,16 @@
import { defineNuxtPlugin } from '#app'
import { useClipboard } from '@vueuse/core'
import { ClipboardPlugin } from '../types'
export default defineNuxtPlugin((nuxtApp) => {
const { copy: copyToClipboard, isSupported } = useClipboard()
function copy (text: string, success: { title?: string, description?: string } = {}, failure: { title?: string, description?: string } = {}) {
if (!navigator?.clipboard) {
if (!isSupported) {
return
}
navigator.clipboard.writeText(text).then(() => {
copyToClipboard(text).then(() => {
if (!success.title && !success.description) {
return
}