uniapp中使用aixos 报错

问题:

在uniapp中使用aixos,运行后报如下错误:

AxiosError: There is no suitable adapter to dispatch the request since : - adapter xhr is not supported by the environment - adapter http is not available in the build

解决方案:配置axios适配器(axios-adapter-uniapp)

Using npm:

复制代码
npm install axios-adapter-uniapp

Using yarn:

复制代码
yarn add axios-adapter-uniapp

使用如下:

复制代码
import axios from 'axios'
import axiosAdapterUniapp from 'axios-adapter-uniapp'
 
const instance = axios.create({
  baseURL: 'URL.com',
  adapter: axiosAdapterUniapp
})