文件上传

上传文件时接口都是需要带上 Token 才能访问的,因此需要组件支持 Header 配置,详细代码见

tools->picture->index.vue

获取Token

  1. import { getToken } from '@/utils/auth'
  2. data() {
  3. return {
  4. headers: {
  5. 'Authorization': getToken()
  6. }
  7. }
  8. }

配置组件

指定 Header :headers="headers"

  1. <!--上传图片-->
  2. <el-upload
  3. :on-preview="handlePictureCardPreview"
  4. :before-remove="handleBeforeRemove"
  5. :on-success="handleSuccess"
  6. :on-error="handleError"
  7. :headers="headers"
  8. :file-list="fileList"
  9. :action="imagesUploadApi"
  10. list-type="picture-card"
  11. >
  12. <i class="el-icon-plus" />
  13. </el-upload>