话不多说 上代码
html
<a-upload
style="margin-left: 8px"
:before-upload="beforeUpload"
:showUploadList="false"
:multiple="false"
:headers="tokenHeader"
>
<a-button> <a-icon type="upload" /> 导入 </a-button>
</a-upload>
提示内容可以根据自己的来
formData是二进制文件流传给后端的
exportUser:后端提供的接口
javascript
import { Modal} from 'ant-design-vue'
beforeUpload(file) {
const formData = new FormData()
formData.append('file', file)
exportUser(formData).then((res) => {
if (res.code == 200) {
Modal.success({
title: '系统提示',
content: res.message,
okText: '知道了',
})
} else {
Modal.error({
title: '系统提示',
content: res.message,
okText: '知道了',
})
}
})
this.getList()
return false
},
javascript
export function exportUser(data){
return axios({
url: '/schedule/createImport',
data: data,
method:'post',
})
}