用console.log()输出一些内容,因为内容太多,显示不完怎么办?如下图所示:
我需要把这个数组保存成一个文本文件。
我的react项目里用的,你改一下就行了。
export const saveJSON = (data: any, filename?: string) => {
if(!filename) filename = `${moment().format(defaultSettings.dateTimeHMSFormat)}.json`;
if(typeof data === "object") data = JSON.stringify(data, undefined, 4);
const blob = new Blob([data], {type: 'text/json'});
const a = document.createElement('a');
a.setAttribute('style', "display: none");
a.download = filename;
a.href = window.URL.createObjectURL(blob);
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':');
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};
13 回答13k 阅读
7 回答2.1k 阅读
3 回答1.3k 阅读✓ 已解决
2 回答1.4k 阅读✓ 已解决
6 回答1.2k 阅读✓ 已解决
6 回答1.1k 阅读
3 回答1.3k 阅读✓ 已解决
你这是 node 呗,直接使用 fs 写文件就得了