1、安装
npm install --save @soerenmartius/vue3-clipboard
2、使用
// main.js
import { createApp } from 'vue'
import App from './App.vue'
import router from "./router";
import { VueClipboard } from "@soerenmartius/vue3-clipboard"
const app = createApp(App);
app.use(router).use(VueClipboard).mount("#app")
<template>
<p v-clipboard:copy="copy_text" v-clipboard:success="onSuccess" v-clipboard:error="onError">{{ copy_text }}</p>
</template>
<script setup>
import { ref } from "vue"
const copy_text = ref("点击复制此消息")
const onSuccess = () => {
alert('复制成功')
}
const onError= () => {
alert('onError')
}
</script>
?点击之后可以粘贴到txt或其他输入框中查看了
|