<el-upload
          list-type="picture-card"
          action=""
          :http-request="uploadFileFn"
          :show-file-list="false"
          :accept="mime"
          :on-change="getFile"
        >
        上传
        </el-upload>
 
methods:{
// 图片转base64    
getFile(file, fileList) {
      this.getBase64(file.raw).then(res => {
        const params = res.split(',')
        console.log(params, 'params')
        if (params.length > 0) {
          this.strimagebase64 = params[1]
        }
      })
    },
    // 获取图片转base64
    getBase64(file) {
      return new Promise(function(resolve, reject) {
        const reader = new FileReader()
        let imgResult = ''
        reader.readAsDataURL(file)
        reader.onload = function() {
          imgResult = reader.result
        }
        reader.onerror = function(error) {
          reject(error)
        }
        reader.onloadend = function() {
          resolve(imgResult)
        }
      })
    }
}
 

相关文章:

  • 2022-12-23
  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2023-01-13
  • 2022-12-23
  • 2021-09-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案