前端数据保存为文件

export function SaveI18N(arr) {
function fakeClick(obj) {
const ev = document.createEvent(‘MouseEvents’);
ev.initMouseEvent(
‘click’,
true,
false,
window,
0,
0,
0,
0,
0,
false,
false,
false,
false,
0,
null
);
obj.dispatchEvent(ev);
}
function exportRaw(name, data) {
const urlObject = window.URL || window.webkitURL || window;
const exportBlob = new Blob([data]);
const saveLink = document.createElementNS(‘http://www.w3.org/1999/xhtml’, ‘a’);
saveLink.href = urlObject.createObjectURL(exportBlob);
saveLink.download = name;
fakeClick(saveLink);
}
let data = ‘’;
for (let i = 0, len = arr.length; i < len; i += 1) {
data = ${data}'${arr[i].key}':'${arr[i].value}',\r\n;
}
exportRaw(‘i18n.txt’, data);
}

你可能感兴趣的:(前端数据保存为文件)