使用input file实现文件上传
const input = document.createElement('input') as HTMLInputElement;
input.type = 'file';
input.accept = 'application/json';
input.addEventListener('change', () => {
const fileList = input.files;
if (fileList?.length !== 1) {
console.error('This is demo feature, you must upload one json file.');
return;
}
const file = fileList.item(0) as File;
const fileReader = new FileReader();
fileReader.readAsText(file, 'UTF-8');
fileReader.onload = () => {
console.log(fileReader.result);
};
});
input.click();

浙公网安备 33010602011771号