直接上代码!!!
async downLoad() {
const file = "你好!123123132";
const blob = new Blob([file], { type: "text/plain;charset=utf-8" }); // 文件流
const options = {
suggestedName: "123.txt", // 默认文件名
};
const handle = await window.showSaveFilePicker(options);
const writable = await handle.createWritable();
await writable.write(blob);
await writable.close();
},
我这里是直接手写了个文件下载,把流换成后端传来的就可以了
PS: 如果你是用的是electron开发,那么你还可以直接使用 “file-saver” 插件
import { saveAs } from "file-saver";
async downLoad() {
const file = "你好!123123132"; // 文件流
const blob = new Blob([file], { type: "text/plain;charset=utf-8" });
saveAs(blob, "你好.txt");
},