文件下载
uploadFile.js
return new Promise((resolve, reject) => {
const input = document.createElement('input')
input.type = 'file'
input.onchange = (event) => {
const file = event.target.files[0]
console.log
}
let elm = document.createElement('input')
elm.setAttribute('type', 'file')
elm.setAttribute('multiple', true)
elm.style.display = 'none'
elm.addEventListener('change', async (e) => {
const files = e.target.files || e.dataTransfer.files
document.body.removeChild(elm)
elm = null
resolve(files)
})
document.body.appendChild(elm)
elm.click()
})
}
引用:
upload().then((files) => {
const formData = new FormData()
for (const f of files) {
formData.append('files', f)
}
//调用接口传入formData
})