Skip to content

Instantly share code, notes, and snippets.

@renzhezhilu
Created October 10, 2019 03:14
Show Gist options
  • Save renzhezhilu/60ec5498bc516cf719eae4ff5f791ed1 to your computer and use it in GitHub Desktop.
Save renzhezhilu/60ec5498bc516cf719eae4ff5f791ed1 to your computer and use it in GitHub Desktop.
[下载文件/bolb转文本文件] #数据转换
//下载文件
// funDownload(JSON.stringify(xxxx),'xxx.json')
function funDownload(content, filename) {
let eleLink = document.createElement('a');
eleLink.download = filename;
eleLink.style.display = 'none';
// 字符内容转变成blob地址
let blob = new Blob([content]);
eleLink.href = URL.createObjectURL(blob);
// 触发点击
document.body.appendChild(eleLink);
eleLink.click();
// 然后移除
document.body.removeChild(eleLink);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment