Loading

两段相同的代码【async await】

async function doSubmitFile() {
  const fileInput = document.getElementById('fileInput')
  const fileObj = fileInput.files[0]

  const formData = new FormData()
  formData.append('file', fileObj)

  try{
    const response = await _axios.post("/api/employ/upload/", formData ,{headers:{'Content-Type': 'multipart/form-data'}})
    console.log(response.data)
  }catch(error){
    ElMessage.error(`文件上传失败,${error}`)
  }
}

function doSubmitFile2() {
  const fileInput = document.getElementById('fileInput')
  const fileObj = fileInput.files[0]

  const formData = new FormData()
  formData.append('file', fileObj)

  _axios.post("/api/employ/upload/", formData, {headers: {'Content-Type': 'multipart/form-data'}}).then((res) => {
    console.log(res.data)
  }).catch((error) => {
    ElMessage.error(`文件上传失败,${error}`)
  })

}
posted @ 2024-10-13 23:27  一只大学生  阅读(3)  评论(0编辑  收藏  举报