zoukankan      html  css  js  c++  java
  • element 上传图片转base64

    <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)
            }
          })
        }
    }
     
  • 相关阅读:
    系统设计5:Google三剑客
    lintcode亚麻九题
    设计模式17:单例模式
    设计模式16:迭代器模式
    设计模式15:组合模式
    476. Number Complement
    561. Array Partition I
    627. Swap Salary
    617. Merge Two Binary Trees
    728. Self Dividing Numbers
  • 原文地址:https://www.cnblogs.com/hellofangfang/p/13366489.html
Copyright © 2011-2022 走看看