概述保存对话框支持类型列表与建议文件名。本文给出类型与 MIME 映射的标准用法。类型映射与保存const types = [

{

description: '文本文件',

accept: { 'text/plain': ['.txt'] }

},

{

description: 'JSON 文件',

accept: { 'application/json': ['.json'] }

}

];

async function saveText(name, text, mime = 'text/plain') {

const handle = await window.showSaveFilePicker({ suggestedName: name, types });

const ws = await handle.createWritable();

const blob = new Blob([text], { type: mime });

await ws.write(blob);

await ws.close();

}

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部