表单formData上传

1.html

<el-upload
    class="filesUpload"
    :action="uploadActionUrl"
    :on-change="operateImage"
    :auto-upload="false"
    :show-file-list="false"
     :limit="1"
>
<el-button size="small" type="primary">点击上传</el-button>

2.js

 // 上传员工图片
    operateImage(file, fileList) {
      const fileType = file.name.substring(file.name.lastIndexOf('.') + 1)
      const types = ['jpeg', 'gif', 'bmp', 'png', 'jpg']
      const isImage = types.includes(fileType)
      if (!isImage) {
        this.$message.error('上传图片只能是 JPG、GIF、BMP、PNG 格式!')
        return
      } else {
        const fd = new FormData()
        fd.append('projectId', getProjectId()) // 参数
        fd.append('image', file.raw) // 图片/文件地址
        uploadImage(fd).then(res => {
          this.imgUser = res[0]
        })
      }
    },

 

posted @ 2020-05-20 15:40  格里兹曼  阅读(190)  评论(0编辑  收藏  举报