vue3 + vue-clipboard3 复制文本到剪切板

1.安装

yarn add vue-clipboard3

2.引入

import useClipboard from 'vue-clipboard3';

3.html部分

<n-button tertiary type="primary" ref="copyBtn" @click="copyPath()">
                复制地址
              </n-button>

4.js部分

复制代码
<script setup lang="ts">
//一键复制
const { toClipboard } = useClipboard();
const copyPreviewPath = async (text?: string) => {
  try {
    await toClipboard('这里传入要复制的文本内容');
    window["$message"].success(text || "复制成功!");
  } catch (e) {
    console.error(e);
    window["$message"].error("复制失败!您的浏览器不支持复制功能!");
  }
};
</script>
posted @ 2023-03-17 11:37  双手插在裤兜谁也不爱  阅读(823)  评论(0)    收藏  举报