vue3 点击复制
npm install clipboard --save //下载
import Clipboard from 'clipboard'//使用页面引入
js:
const copyText = async () => { const text = window.location.href // 设置要复制的文本 let clipboard = new Clipboard('.buttoncopy', { text: () => text }) clipboard.on('success', (e) => { alert('已成功复制到剪贴板,请打开浏览器,在地址栏粘贴访问') e.clearSelection() // 清除选中状态 }) clipboard.on('error', function (e) { text1.value = window.location.href alert('无法复制到剪贴板,请长按下边链接手动复制') }) }
html: <p class="buttoncopy" @click="copyText">点此复制链接</p>