上傳圖片生成base64

我の前端日记發表於2024-11-15
// 圖片生成base64格式
function handleFileChange(event) {
  const file = event.target.files[0]
  if (file) {
    const reader = new FileReader()
    reader.onload = (e) => {
      imageBase64.value = e.target.result
    }
    reader.readAsDataURL(file)
  }
}

async function uploadImage() {
  if (imageBase64.value) {
    const param = {
      url: imageBase64.value,
      path: imageBase64.value,
      name: imageBase64.value,
      file: imageBase64.value,
    }
    apiUserlist.uploadimg(param).then((res: any) => {
      console.log('uploadimg', res.data)
    })
  }
}

相關文章