导出
程序员文章站
2022-03-15 12:58:00
...
fakeClick(obj) {
var ev = document.createEvent("MouseEvents");
ev.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
obj.dispatchEvent(ev);
},
exportRaw(name, data) {
var urlObject = window.URL || window.webkitURL || window;
var export_blob = new Blob([data]);
var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
save_link.href = urlObject.createObjectURL(export_blob);
save_link.download = name;
this.fakeClick(save_link);
}
//从后台请求到的数据,可以传给exportTxt
exportTxt(10581).then(res=>{
this.exportRaw('result.txt',res);
})