element-ui upload组件支持multipart/form-data格式

设置with-credentials属性即可支持

<template>
 <el-upload
    ref="upload"
    drag
    :action="action"
    with-credentials
    :auto-upload="false"
    :on-success="handleSuccess"
    :on-error="handleError"
    >
    <i class="el-icon-upload"></i>
    <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  </el-upload>
</template>

<script>
export default {
  methods: {
    handleSuccess(res) {
      const { code } = res
      if (code === 1) {
        this.$message({
          message: '上传成功!',
          type: 'success',
        })
      }
      this.$refs.upload.clearFiles()
      this.hide()
    },
    handleError() {
      this.$message({
        message: '上传失败!',
        type: 'error',
      })
    },
  },
}
</script>
上一篇:layui中的select的onchange监听失效事件


下一篇:el-form,动态校验+自定义方法