+
95
-

js中如何将数组下载保存文件,然后再打开文件还原成数组?

js中如何将数组下载保存文件,然后再打开文件还原成数组?

网友回复

+
15
-
// 将数组保存为文件
function downloadArrayAsFile(array, filename) {
  const jsonStr = JSON.stringify(array);
  const blob = new Blob([jsonStr], { type: 'application/json' });
  const url = URL.createObjectURL(blob);

  const a = document.createElement('a');
  a.href = url;
  a.download = filename;
  a.style.display = 'none';

  document.body.appendChild(a);
  a.click();
  document.body.removeChild(a);
...

点击查看剩余70%

我知道答案,我要回答