axios 真机调试报错:TypeError: adapter is not a function,h5正常,解决方法?axios接口封装,uniapp接口封装,vue接口封装,请求拦截,请求返回拦截

axios 真机调试报错:TypeError: adapter is not a function,h5正常,解决方法?axios接口封装,uniapp接口封装,vue接口封装,请求拦截,请求返回拦截

时空书城-出品 import axios from ‘axios’ import common from “@/common/common.js” import store from ‘@/store/store.js’ let BASE_URL = ‘’; let BASE_WS_URL = ‘’; const BASE_URL_ADMIN_PATH = ‘/api’; let ceshi = ‘’ //请求域名 let bendi = ‘******.com’ //本地开发 let production = ‘******.com’ //测试服 //WebSocket地址、 let bendiWs = ‘******.com’ //本地开发 let productionWs = ‘******.com’ //测试服 if (process.env.NODE_ENV === ‘development’) { BASE_URL = bendi //开发 BASE_WS_URL = bendiWs } else { BASE_URL = production // 线上 BASE_WS_URL = productionWs } // 状态码 const BASE_TIMEOUT = 5000; //请求超时 默认5000 const AUTH_TOKEN_FLAG = ‘admin_auth_token’; //token const TOKEN_LOGIN_CODE = 995; //请先登录 const TOKEN_INVALID_CODE = 996; //无效令牌! const TOKEN_RESERVED_ERROR_CODE = 997; //保留错误码! const TOKEN_Undefined_CODE = 998; //请求对象未定义! const TOKEN_System_exception_CODE = 999; //系统异常! /** 所有接口变量定义 */ const apiList = { getToken: ‘/Auth/getToken’, //获取游客token } /** 请求网络变量定义 */ const instance = axios.create({ baseURL: BASE_URL + BASE_URL_ADMIN_PATH, timeout: BASE_TIMEOUT, }); // 请求拦截器 instance.interceptors.request.use(config => { let token = uni.getStorageSync(AUTH_TOKEN_FLAG); config.headers.common['token'] = token return config; }, error => { return Promise.reject(error); }); 时空书城-出品 // 返回拦截 instance.interceptors.response.use((response) => { switch (response.data.code) { case TOKEN_LOGIN_CODE: // 登录状态改为false uni.setStorage({ key: ‘isLogin’, data: false, }); uni.showToast({ title: ‘请先登录’, icon: ‘none’ }) setTimeout(() => { uni.navigateTo({ url: ‘/pages/login/login’ }); }, 2000) break; case TOKEN_INVALID_CODE: // 无效令牌 // 清除token uni.setStorage({ key: ‘token’, data: ‘’, success: function() { // 获取token https(apiList.getToken + ${common.getData}).then(response => { if (response.status == 200) { uni.setStorage({ key: ‘token’, data: response.data.data.token, success() { //从新加载方法1 /* #ifdef H5 / location.reload() / #endif */ } }); } }); } }); break; case common.code: response.data.msg = ‘成功’ break; } return response; }, function(error) { return Promise.reject(error); }); 时空书城-出品 //app真机获取 instance.defaults.adapter = function(config) { return new Promise((resolve, reject) => { 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); } }) }) } /** * 网络请求 * @param {String} url 请求地址 * @param {Array} data 请求数据 */ function https(url, data = null) { return new Promise((resolve, reject) => { let lodingIsShow = uni.getStorageSync('lodingIsShow'); if(!lodingIsShow){ lodingIsShow = false uni.setStorage({ key: 'lodingIsShow', data: true, }); setTimeout(function(){ uni.showLoading({ title: '加载中' }); },400) } instance.request({ //请求 后台路由 //baseURL: BASE_URL + BASE_URL_ADMIN_PATH, //url 为 封装好的 method: (data === null) ? 'get' : 'post', //如果data=null 就是get请求 如果 有带参数就是post请求 url: BASE_URL + BASE_URL_ADMIN_PATH + url, data: data }).then((response) => { setTimeout(function(){ uni.hideLoading(); uni.setStorage({ key: 'lodingIsShow', data: false, }); },100) resolve(response); }).catch((error) => { setTimeout(function(){ uni.hideLoading(); uni.setStorage({ key: 'lodingIsShow', data: false, }); },100) reject(error) }) }); } 时空书城-出品 export default { apiList, https, BASE_URL, BASE_URL_ADMIN_PATH, BASE_WS_URL, } 时空书城-出品

都市极品医神(叶辰夏若雪孙怡)小说,最新章节阅读

都市极品医神(叶辰夏若雪孙怡):第1章 滚吧! 我不想杀人!, 【火爆爽文】“古武者?地狱归来?华夏第一人?我惹不起?不好意思,在我面前,都要跪下!”五年前,家族覆灭,废物叶辰犹如地上蠕虫般被人耻笑!但是五年后,他带着一身逆天术法强势回归!更可怕的是,他背后还站.. ,免费阅读时空书城

如果这个文章对你有帮助,请支持下站长的努力付出,点击下方是本人的网站:时空书城,谢谢

时空书城