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"),
},