uni.uploadfile和request请求我在使用的时候,看Network里面两个都发送请求,没有仔细观察过,以为这两个区别不大都会发起请求,但是今天在使用的时候,我发现了一个uni.uploadfile的问题。
我在请求拦截器里面添加了附带token的代码,如下图
if(token){
config.header = {
'content-type': 'application/x-www-form-urlencoded',
'token': token
}
}
但是使用uni.uploadfile的时候发现请求头里面并没有token传过去,所以就造成了代码有问题
解决当然也很简单,可以在uni.uploadfile里面配置一下header头就可以了
uni.uploadFile({
url: url,
files:this.submitList,
formData: this.formDatas,
header:{
'token': token
},
success: (uploadFileRes) => {
}
});