el-upload 上传多张图片,采用formData方式上传

            
              
            
            
              //图片预览的弹框
            
export dafault {
  data (){
    return {
        dialogImageUrl: '',
        imageList:[],
        fileList:[],
      }
  },
methods:{
      //删除已上传图片
      handleRemove(file, fileList) {
        //file是当前删除的图片,fileList是已上传图片列表
          this.imageList =fileList
          this.fileList = fileList
        },
      //图片预览
      handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
        },
      // 上传成功时的钩子
      uploadSuccess(file,fileList){
        console.log(fileList)
        let that =this
        var fileType = file.raw.type;
        var isJpg = false;
        if (fileType == 'image/jpeg' || fileType == 'image/png' || fileType == 'image/jpg') {
            isJpg = true;
        }           
        if (!isJpg) {
            this.$message({
            message: '上传的图标只能是jpg、png格式!',
            type: 'error'
          });
          return false
        }
         this.fileList= fileList
        this.imageList =fileList
      },
        let formList = new FormData();
        this.fileList.forEach( (file)=>{
          formList.append('fileList', file.raw);
        })
      //formList就是传给后台的值啦
  }
}

你可能感兴趣的:(el-upload 上传多张图片,采用formData方式上传)