表格里面实现点击复制每一行的特定值

502 阅读1分钟

首先,表格样式(部分)

<el-table :data="list" style="width: 100%" >
    ...
    <el-table-column label="操作" >
        <template scope="scope">
            <el-button type="text" @click="copyText(scope.row)">复制</el-button>  //点击复制
        </template>
    </el-table-column>
    ...
</el-table>
copyText(row) {
   console.log(row);  //每一行的数据
   var copyUrl= row.url;  //每一行的某个值,如选中的当前行的url
    var oInput = document.createElement('input');     //创建一个隐藏input(重要!)
    oInput.value = copyUrl;    //赋值
    document.body.appendChild(oInput);
    oInput.select(); // 选择对象
    document.execCommand("Copy"); // 执行浏览器复制命令
    oInput.style.display='none';
    alert('复制成功');
},

在这里插入图片描述 在这里插入图片描述