Fork me on github

上传图片生成base64

// 图片生成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)
    })
  }
}

 

<input type="file" @change="handleFileChange">
      <button @click="uploadImage">
        上传图片
      </button>

 

posted @ 2024-11-15 16:21  我の前端日记  阅读(1)  评论(0编辑  收藏  举报
Copyright © 2021 LinCangHai
Powered by .NET 5.0 on Kubernetes