vue el-upload 上传接口增加 token
上传导入时,接口需要携带 token ,组件用的是 el-upload ,我们把 token 放到 headers 里即可。
·
上传导入时,接口需要携带 token ,组件用的是 el-upload ,我们把 token 放到 headers 里即可
<el-upload
class="upload-demo"
action="https://jsonplaceholder.typicode.com/posts/"
:data="importData"
:show-file-list="false"
:on-success="handleSuccess"
:headers="headers"
>
<el-button size="small" type="primary">点击上传</el-button>
</el-upload>
<script>
export default {
data() {
return {
headers:{},
importData:{imporType: 1},
token:""
},
mouted() {
this.token = localStorage.getItem("token")
this.headers = {token: this.token}
}
methods: {
handleSuccess(response){
if(response.responseCode == 0) {
this.$message.success(response.responseMsg)
} else {
this.$message.error(response.responseMsg)
}
}
}
}
</script>
更多推荐
已为社区贡献3条内容
所有评论(0)