1.安装依赖
npm install vue-clipboard3 --save
2.使用案例
<template lang="html">
<button @click="copy">copy</button>
</template>
<script lang="ts" setup>
//引入
import useClipboard from 'vue-clipboard3'
const { toClipboard } = useClipboard()
const copy = async () => {
try {
await toClipboard('需要复制的链接')
$message.success('复制成功')
} catch (e) {
console.error(e)
$message.error('复制失败')
}
}
</script>