一、首先,安装 vue-clipboard3
:
npm install vue-clipboard3
二、在你的 Vue 3 项目中使用它:
<template>
<i @click="copy((text1))">{{ text1 }}</i>
</template>
<script setup>
import clipboard3 from 'vue-clipboard3'
const text1 = ref('text1')
const { toClipboard } = clipboard3()
const copy = async (text) => {
try {
await toClipboard(text);
} catch (error) {
console.error(error);
}
}