vue에서 사용가능.
// excel Download
const excelFileDownload = async () => {
// eslint-disable-next-line max-len
const fileUrl = '파일주소';
const res = await axios({
method: 'get',
url: fileUrl,
responseType: 'blob',
});
const newUrl = window.URL.createObjectURL(res.data);
const a = document.createElement('a');
a.href = newUrl;
a.download = '파일명.확장자';
a.click();
a.remove();
window.URL.revokeObjectURL(newUrl);
};
// excel Upload
const inputFileUpload = ref(); // 태그에 대한, ref
const fileUpload = () => {
const input = inputFileUpload.value as HTMLInputElement;
input.click();
};
const readFile = async () => {
const input = inputFileUpload.value as HTMLInputElement;
if (input && input.files) {
const targetFile = input.files[0];
const formData = new FormData();
formData.append('file', targetFile);
const res = await requestApiFunction({
params: formData
});
if (res.isOK) {
// ok 처리
}
}
};