ant-upload上传成功
<template>
<div>
<a-upload
name="file"
:multiple="true"
:action="path"
:headers="headers"
:beforeUpload="beforeUploadMains"
:default-file-list="fileList"
@change="handleChange"
>
<a-button size="small"> <a-icon type="upload" /> 上传文件 </a-button>
</a-upload>
</div>
</template>
<script>
export default {
name: 'singleUpload',
props: {
fileList: Array,
},
data() {
return {
path: `${
process.env.VUE_URL}/aaaaa`,
headers: {
authorization: 'authorization-text',
token: JSON.parse(localStorage.getItem('pro__Access-Token')).value
},
}
},
methods: {
beforeUploadMains(file) {
return new Promise((resolve, reject) => {
if (file.name.substr(-4) !== 'doc') {
this.$message.warning('上传文件只能是doc格式!')
return reject(false)
} else {
resolve(true)
}
const isLt10M = file.size / 1024 / 1024 < 10
if (!isLt10M) {
this.$message.warning('上传文件大小不能超过 10MB!')
return reject(false)
} else {
resolve(true)
}
})
},
handleChange(info) {
if(info.file.status == "done"){
if(info.file.response.status == '1'){
this.$message.success('文件上传成功!')
let datas = info.file.response.data
this.$emit('onSuccess', datas)
} else {
this.$message.warning('上传文件为不可解析文件!')
}
}
},
},
}
</script>