Skip to content

Instantly share code, notes, and snippets.

@rettuce
Last active October 20, 2022 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rettuce/4522a3a8c06e2f4aaae61d7cb289b7b0 to your computer and use it in GitHub Desktop.
Save rettuce/4522a3a8c06e2f4aaae61d7cb289b7b0 to your computer and use it in GitHub Desktop.
File System Access API を使って Vue.js でObjectをjsonファイルにローカル保存。
fileSave( output_obj:Object ) {
let saveFileOptions = {
suggestedName: "xxxxxx.json",
types: [
{
description: "JSON Files",
accept: {
"application/json": [".json"],
},
},
],
};
(async () => {
let blob = new Blob([JSON.stringify(output_obj, null, " ")], {
type: "application/json",
});
const handle = await window.showSaveFilePicker(saveFileOptions);
await this.writeFile(handle, blob);
console.log("save comp!!");
})();
}
async writeFile(fileHandle, contents) {
const writable = await fileHandle.createWritable();
await writable.write(contents);
await writable.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment