• 周五. 4月 26th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

vue 3 的复制功能 vue-clipboard3

admin

11月 28, 2021

yarn add vue-clipboard3

or

npm install --save vue-clipboard3




<template lang="html"> <div> <input type="text" v-model="text"> <button @click="copy">Copy!</button> </div> </template> <script lang="ts"> import { defineComponent, ref } from '@vue/composition-api' import useClipboard from 'vue-clipboard3' export default defineComponent({ setup() { const { toClipboard } = useClipboard() const text = ref('') const copy = async () => { try { await toClipboard(text.value) console.log('Copied to clipboard') } catch (e) { console.error(e) } } return { copy, text } } }) </script>

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注