<template>
<el-table :data="tableData" style="width: 100%">
<el-table-column prop="date" label="日期" width="180"></el-table-column>
<el-table-column prop="name" label="姓名" width="180"></el-table-column>
<el-table-column prop="address" label="地址"></el-table-column>
<el-table-column label="操作" width="150">
<template slot-scope="scope">
<el-button @click="copyRowData(scope.row)" size="small">复制</el-button>
</template>
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [
{
date: '2016-05-02',
name: '张三',
address: '上海市普陀区金沙江路 1518 弄'
},
// ... 更多数据
]
};
},
methods: {
copyRowData(row) {
const { clipboard } = require('electron');
clipboard.writeText(JSON.stringify(row));
this.$message.success('复制成功');
}
}
};
</script>
在这个示例中,我们定义了一个tableData
数组来模拟表格数据。在el-table-column
中使用slot-scope
来访问每一行的数据,并在操作列中添加了一个按钮,当按钮被点击时,调用copyRowData
方法。该方法接收当前行的数据,将其转换为JSON字符串,并使用Electron的clipboard
模块将其复制到剪贴板。最后,使用Element UI的$message.success
方法来显示复制成功的提示信息。
注意:这个示例假设你正在使用Electron框架,因为clipboard
模块是Electron提供的。如果你不是在Electron中工作,你可能需要使用其他方式来处理剪贴板操作,例如使用navigator.clipboard
API在标准浏览器中。