最近实现了一个小功能——复制文本到剪贴板: 具体实现步骤有以下几步
el-table代码如下
<el-table-column
width="500px"
prop="category.linkJson"
label="访问地址"
>
<template slot-scope="scope">
<el-input
:ref="`popovers-${scope.$index}`"
style="width: 380px"
v-model="scope.row.add"
placeholder="请输入内容"
>
<i
slot="suffix"
@click.stop="copy(scope.$index)"
style="
font-style: normal;
color: #1890ff;
cursor: pointer;
display: inline-block;
height: 28px;
line-height: 28px;
"
>复制</i
>
</el-input>
</template>
</el-table-column>
copy事件代码如下
navigator.clipboard.writeText('复制的内容').then(() => {
this.$message({
message: "复制成功",
type: "success",
});
});