您的当前位置:首页正文

在ElementUI的上传组件el-upload中设置header

2024-11-28 来源:个人技术集锦
axios.interceptors.request.use(config=>{
  NProgress.start();
  // 发送请求需带上token
  config.headers.Authorization=window.sessionStorage.getItem("token")
  return config;
})
 <el-upload
              action="http://127.0.0.1:8888/api/private/v1/upload"
              :headers="headerObj"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :on-success="handleSuccess"
              list-type="picture"
            >
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">
                只能上传jpg/png文件,且不超过500kb
              </div>
            </el-upload>

在data中定义headerObj

headerObj: {
        Authorization: window.sessionStorage.getItem("token"),
      },
显示全文