fix click textarea.

This commit is contained in:
2023-03-30 09:46:39 +08:00
parent c97b2c4879
commit 301fc1be6d
6 changed files with 63 additions and 22 deletions

23
src/utils/download.ts Normal file
View File

@@ -0,0 +1,23 @@
import axios from "axios"
const http = axios.create({
baseURL: "/api/admin",
responseType: "blob",
xsrfHeaderName: "X-CSRFToken",
xsrfCookieName: "csrftoken",
})
async function download(url: string) {
const res = await http.get(url)
const headers = res.headers
const link = document.createElement("a")
link.href = window.URL.createObjectURL(
new window.Blob([res.data], { type: headers["content-type"] })
)
link.download = (headers["content-disposition"] || "").split("filename=")[1]
document.body.appendChild(link)
link.click()
link.remove()
}
export default download