Element UI 表格复制物流单号功能实现 - JavaScript 代码示例
<el-table-column label="退货物流单号" prop="deliveryNo" width="150"> <template #default="scope"> <div> <span>{{ scope.row.deliveryNo }}</span> <el-button type="primary" size="small" link @click="copyText(scope.row.deliveryNo)">copy </el-button> </div> </template> </el-table-column>
function copyText(text) { console.log('啊啊啊',text);
};
这个查到的结果是数字,点击copyText按钮之后能把这串数字复制到剪切板内容:您可以使用以下代码将文本复制到剪贴板:
function copyText(text) {
const input = document.createElement('input');
input.value = text;
document.body.appendChild(input);
input.select();
document.execCommand('copy');
document.body.removeChild(input);
console.log('已复制到剪贴板', text);
}
在您的代码中调用copyText函数时,它将把传递给它的文本复制到剪贴板。
<el-table-column label="退货物流单号" prop="deliveryNo" width="150">
<template #default="scope">
<div>
<span>{{ scope.row.deliveryNo }}</span>
<el-button type="primary" size="small" link @click="copyText(scope.row.deliveryNo)">copy </el-button>
</div>
</template>
</el-table-column>
原文地址: https://www.cveoy.top/t/topic/qt1D 著作权归作者所有。请勿转载和采集!