使用vue-cli创建的uniapp项目,在封装axios时,写了如下代码:
axiosInter.defaults.adapter = function (config) {
return new Promise((resolve, reject) => {
// console.log(config)
var settle = require("axios/lib/core/settle");
var buildURL = require("axios/lib/helpers/buildURL");
uni.request({
method: config.method.toUpperCase(),
url: buildURL(config.url, 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);
},
});
});
};
require('axios/lib/core/settle')时报错Module not found: Error: Package path ./lib/core/settle is not exported from package D:\cloud2\uniapp\node_modules\axios,
require("axios/lib/helpers/buildURL")时也同样报错
解决办法:package.json中查看axios版本为1.3.4,为当前最新版本,猜测是因为版本太高导致,于是重新下载旧版本0.26.1,重新启动项目无报错。