Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VM515:1 MiniProgramError Cannot read property 'defaults' of undefined TypeError: Cannot read property 'defaults' of undefined #23

Open
bosens-China opened this issue Aug 4, 2020 · 0 comments

Comments

@bosens-China
Copy link

问题是什么

直接按照实例引用报错

import axios from 'axios'
import mpAdapter from 'axios-miniprogram-adapter'
axios.defaults.adapter = mpAdapter
const instance = axios.create({
  baseURL: 'http://tms.vicici.com:9002/'
});

// 添加请求拦截器
instance.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么
  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});

// 添加响应拦截器
instance.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  return response;
}, function (error) {
  // 对响应错误做点什么
  return Promise.reject(error);
});

export default instance;

环境

  • 环境:微信开发者工具最新版

在线例子

尽可能提供在线例子

报错信息

VM515:1 MiniProgramError
Cannot read property 'defaults' of undefined
TypeError: Cannot read property 'defaults' of undefined

小程序npm编译后的目录图如下

axios
├─ index.js
└─ index.js.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant