Hi mn,
Em muốn khi click vào button download thì tải về file template.
E đặt file template vào cùng thư mục.
Đây là đoạn code:
import batchTemplate from "./template.xlsx"; function downloadTemplate() { axios({ url: batchTemplate, method: "GET", headers: { "Content-Disposition": "attachment; filename=template.xlsx", "Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }, responseType: "arraybuffer" }).then(response => { console.log(response); const url = window.URL.createObjectURL(new Blob([response.data])); console.log(url); const link = document.createElement("a"); link.href = url; link.setAttribute("download", "template.xlsx"); //or any other extension document.body.appendChild(link); link.click(); }); }
Chạy local ok. Nhưng lên server thì lỗi.
Mong ace support. Thanks ace nhiều.
anh chưa làm kiểu này bao giờ nhưng anh đoán là sẽ không được, anh thấy em phải để cái file template của em ra 1 cái host nào đó, sau em sẽ download cái file từ cái host đó, chứ không thể import file vào sau download kiểu kia được em ạ.
P/S: em dùng thẻ pre để paste code nhé
thanks a. e cũng nghĩ vậy