1 真机无法调取api
// 解决方案 安装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({
...
adapter: axiosAdapterUniapp
})
2 关于“request:fail abort statusCode:-1 Expected URL scheme ‘http‘ or ‘https‘ but was 'file'”报错处理
解决方案
在main.js中添加区分环境的语法
if(process.env.NODE_ENV === 'development'){
//开发环境
// #ifdef H5
// 如需跨域参照以下h5跨域配置
baseUrl = "/api"
// #endif
// #ifdef APP-PLUS ||MP
baseUrl = "http://192.168.1.200:8445/dev"
// #endif
}else{
baseUrl = ""
}
在manifest.json中"h5"添加如下跨域配置
"devServer" : {
"hot":true,
"host":"localhost",
"port" : 8080,
"disableHostCheck" : true,
"proxy" : {
"/api" : {
"target" : "http://192.168.1.200:8445/dev", // 需要跨域的域名
"changeOrigin" : true,
"secure" : false,
"pathRewrite" : {
"^/api" : ""
}
}
}