element UI base64格式上传图片

element UI base64格式上传图片

<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="150px" class="demo-ruleForm" label-position="left">
  <el-form-item label="系统logo" prop="logoPhoto">
    <el-upload class="avatar-uploader" action="" :show-file-list="false" :auto-upload="false" :on-change="changeFile"> 
      <img :src="ruleForm.logoPhoto" class="avatar">
      <el-button slot="trigger" size="small" type="primary">上传</el-button>
    </el-upload>
  </el-form-item>
</el-form>


<script>
export default {
  data() {
    return {
      imageUrl: '',
      ruleForm: {
        logoPhoto: ''
      },
    };
  },
  created () {
    getSystemConfig(this.community.communityId)  // 调用接口获取已有信息
      .then(({ data }) => {
        console.log("data,,..", data);
        // 刚开始因为没有注意到created里面这句话对ruleForm对象进行了修改,导致上传图片后界面一直不显示图片
        // this.ruleForm = data || {systemName: this.community.systemName};
        this.ruleForm.systemName = data.systemName || this.community.systemName;
        this.ruleForm.logoPhoto = data.uloge || undefined;
      })
  },
  methods: {
    // 上传图片
    changeFile(file) {
      var This = this;
      var reader = new FileReader();
      reader.readAsDataURL(file.raw);
      reader.onload = function(){ 
        // this.result // 这个就是base64编码了
        This.ruleForm.logoPhoto = this.result;
        This.imageUrl = this.result.substring(23);
      }
    },
  },
}
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值