项目需求,需要将页面上的数据生成文本,或者excel导出到本地,选用fileSaver.js
1.安装
npm install file-saver --save
2.导出
exportText() {
let str = '文件的内容';
let FileSaver = require('file-saver');
let blob = new Blob([str], {type: 'text/plain;charset=utf-8'});
FileSaver.saveAs(blob, '文件名.txt');
}
exportExcel() {
let str = ' "name":"张三 " ';
let FileSaver = require('file-saver');
let blob = new Blob([str], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
FileSaver.saveAs(blob, '文件名.xls');
}
网友评论