设置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>