0
uni-app使用axios发送请求时adapter is not a function
黄粱一梦2024-01-1720
uni-app使用axios发送请求时adapter is not a function
解决app上adapter is not a function问题
import axios from 'axios'
import axiosAdapterUniapp from 'axios-adapter-uniapp'
//真机获取 解决app上adapter is not a function问题
axios.defaults.adapter = function(config) {
return new Promise((resolve, reject) => {
var settle = require('axios/lib/core/settle');
var buildURL = require('axios/lib/helpers/buildURL');
var buildFullPath = require('axios/lib/core/buildFullPath');
let fullurl = buildFullPath(config.baseURL,config.url)
uni.request({
method: config.method.toUpperCase(),
url: buildURL(fullurl, config.params, config.paramsSerializer),
header: config.headers,
data: config.data,
dataType: config.dataType,
responseType: config.responseType,
sslVerify: config.sslVerify,
complete:function complete(response){
response = {
data: response.data,
status: response.statusCode,
errMsg: response.errMsg,
header: response.header,
config: config
};
settle(resolve, reject, response);
}
})
})
}
const instance = axios.create({
adapter:axiosAdapterUniapp
})
export default instance
版权声明
本文系作者 @黄粱一梦 转载请注明出处,文中若有转载的以及参考文章地址也需注明。\(^o^)/~
Preview