Last active
October 20, 2022 07:52
-
-
Save rettuce/4522a3a8c06e2f4aaae61d7cb289b7b0 to your computer and use it in GitHub Desktop.
File System Access API を使って Vue.js でObjectをjsonファイルにローカル保存。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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