首页 > 其他分享 >在uniapp中使用axios出现adapter is not a function的解决方案

在uniapp中使用axios出现adapter is not a function的解决方案

时间:2022-08-26 17:57:06浏览次数:61  
标签:function uniapp axios data header config response

出现这种报错是因为uniapp对axios有适配问题,不兼容,需要在main.js或者封装axios的文件中加以下代码

axios.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: config.baseURL + 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);
          }
      })
  })
}

 

标签:function,uniapp,axios,data,header,config,response
From: https://www.cnblogs.com/wjw66/p/16628462.html

相关文章

  • uniapp相关功能实现
    1.实现下拉刷新和触底刷新,其实很简单,就在pages.json的pages数组内,对需要实现效果的页面加两句代码,大概如下{"path":"pages/post/home","style":{"en......
  • 在uniapp目录下的uni_module中创建自定义组件
    一、前言  在使用uni-app框架时,可能里面的内置组件和扩展组件都不是我们想要的,或者不能满足我们的需求,这时就必须得创建自定义组件了,在低版本的HbuilderX中所有的组......
  • axios封装loading加载
    实现如下图效果  点击获取数据按钮出现loading效果1.定义一个Loading组件<template><divv-if="isShow"class="box"><divclass="container"><div......
  • axios请求响应拦截器的应用
    什么是axios拦截器?一般在使用axios时,会用到拦截器的功能,一般分为两种:请求拦截器、响应拦截器。请求拦截器在请求发送前进行必要操作处理例如添加统一cookie、请求体加......
  • sprintf': This function or variable may be unsafe. Consider using sprintf_s
    在vs里面写c会报各种奇怪的错误,那就用cpp吧,然后c里面的一些函数也会报错,包括最常用的sprintf:sprintf:Thisfunctionorvariablemaybeunsafe.Considerusingsprint......
  • Verilog中函数function写法使用方法
    function写法function的标准写法如下:  函数的语法为:.定义函数时至少要有一个输入参量;可以按照ANSI和module形式直接定义输入端口。例如:function[63:0]alu(input[......
  • axios 取消请求
    axios参考文档:https://www.axios-http.cn/docs/cancellation 注:使用mock模块,模拟接口数据,个人测试,是无法取消请求的。  配置axios//axios.get(url,config)//如......
  • 即时通讯源码(基于websocket即时通讯源码uniapp)+视频搭建教程
    即时通讯系统源码服务器端构架目录:1、构建基本服务器2、用户在线功能3、用户消息广播机制4、用户业务层封装5、在线用户查询6、修改用户名......
  • uniapp 打开 外部app某个页面
    配置manifest.json->urlschemewhitelist白名单/*ios打包配置*/"ios":{"UIBackgroundModes":["audio"],"urlschemewhitelist":["baidumap","iosa......
  • 微信小程序开发工具,更新后报typeof4 is not a function
    升级开发者工具版本后,新版工具将es6转es5和增强编译合并,报以下错误。  解决方法有两种:1.修改一下@babel/runtime/helpers/typeof.js文件,内容修改为代码片段的。......