下载文件

75 阅读1分钟

// 创建JSON文件

createJSONBlob(json) {

const blob = new Blob([JSON.stringify(json)], {

type: 'application/json'

}),

jsonFileURL = window.URL.createObjectURL(blob),

{fontName} = this.state.options;

this.downloadURL(jsonFileURL, `${fontName}.json`);

}

// 下载文件

downloadURL(data, fileName) {

const a = document.createElement('a');

a.href = data;

a.download = fileName;

document.body.appendChild(a);

a.style = 'display: none';

a.click();

a.remove();

}