Element upload component upload pictures and echo images

Scene: the need to add new merchandise goods main view, editable after new success

upload image:

<el-form-item label="专区logo:" style="height:160px">
            <div class="img">
              <el-upload
                action="https://testopenapi.nbdeli.com/crm/customer/saveChannelLogoFile"
                :limit="1"
                :on-preview="handlePictureCardPreview"
                :on-success="handleUploadSuccess"
                list-type="picture-card"
                :on-remove="handleRemove"
                :class="{disabled:uploadDisabled}"
                :file-list="fileList"
              >
                <i class="el-icon-plus"></i>
              </el-upload>
              <el-dialog :visible.sync="dialogVisible">
                <img width="100%" :src="ruleForm.dialogImageUrl" alt />
              </el-dialog>
            </div>
            <div class="imgSpan2">只能上传jpg/png文件,50X50px</div>
          </el-form-item>
data(){
  return{
    uploadDisabled: false,
        logoId: "1", //专区logo id
       dialogVisible: false,
      fileList: [], 
       ruleForm: { 
        dialogImageUrl: "1", after the area // logo uploaded to the background, the background will return an id, just give backstage pass id, but click on the background when editing the return address is http 
      } 
   }   
}
 
 
// delete pictures
handleRemove(file, fileList) {
console.log(file);
this.uploadDisabled = false;
},
//上传中
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      console.log(this.dialogImageUrl);
      this.dialogVisible = true;
      this.uploadDisabled = true;
    },
    //上传成功
    handleUploadSuccess(file) {
      this.ruleForm.dialogImageUrl = file.result; //专区logoId
      this.uploadDisabled = true;
    },

Picture upload is complete

 

The following is an edited picture;

Click Edit in time, get url address 
the need to add to url inside fileList
let urlStr = response.data.result.url.split(","); //logo地址
          urlStr.forEach(item => {
            let obj = new Object();
            obj.url = item;
            this.fileList.push(obj);
          });

 

Guess you like

Origin www.cnblogs.com/lidonglin/p/11577602.html