文件上传
上传文件时接口都是需要带上 Token 才能访问的,因此需要组件支持 Header 配置,详细代码见
tools->picture->index.vue
获取Token
import { getToken } from '@/utils/auth'
data() {
return {
headers: {
'Authorization': getToken()
}
}
}
配置组件
指定 Header :headers="headers"
<!--上传图片-->
<el-upload
:on-preview="handlePictureCardPreview"
:before-remove="handleBeforeRemove"
:on-success="handleSuccess"
:on-error="handleError"
:headers="headers"
:file-list="fileList"
:action="imagesUploadApi"
list-type="picture-card"
>
<i class="el-icon-plus" />
</el-upload>