对应导出按钮绑定事件函数如下:
function exportData() {
const headerStrList = ['姓名', '年纪', '性别'];
const dataArr = [];
this.tableData.forEach(item => {
const arr = [item.name, item.age, item.gender];
dataArr.push(arr);
}
const excelList = [];
excelList.push(headerStrList.join('\t,') + '\n');
dataArr.forEach(item => {
excelList.push(item.join('\t,') + '\n');
})
const exportStr = excelList.join('');
const uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(exportStr);
const link = document.createElement('a');
link.href = uri;
link.download = '下载表格数据.csv';
link.click();
}
//notice:不想要csv格式的数据,将下载文件的文件名后缀改成xlsx也可以