CopyButton 复制按钮
一键复制文本,基于 Clipboard API 并带降级处理。
基础用法
vue
<template>
<div class="flex items-center gap-2">
<span>{{ text }}</span>
<CopyButton :text="text" />
</div>
</template>
<script setup lang="ts">
const text = ref('这是要复制的文本')
</script>1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
表格中使用
vue
<el-table-column label="手机号" prop="mobile">
<template #default="{ row }">
<span>{{ row.mobile }}</span>
<CopyButton v-if="row.mobile" :text="row.mobile" />
</template>
</el-table-column>1
2
3
4
5
6
2
3
4
5
6
自定义内容
vue
<CopyButton :text="text">
<el-button type="primary" size="small">复制链接</el-button>
</CopyButton>1
2
3
2
3
Props
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
text | 要复制的文本 | string | '' |
style | 自定义样式 | object | {} |
Slots
| 插槽名 | 说明 |
|---|---|
| default | 自定义按钮内容 |
