axios封装接口之后,调用相应接口是提示.then is not a function

company.jsx文件

import request from '../utils/request';//http地址

function getCompanyList() {
  return request({
    method: 'GET',
    url: '/company/getCompanyList'
  });
}

export default getCompanyList;

api 文件

import getProductList from './products';
import getCompanyList from './company';

export default {
  getProductList,
  getCompanyList
};

引用api文件

api.getCompanyList.then((res) => {
  console.log(res);
});

报错:
TypeError: _api_index__WEBPACK_IMPORTED_MODULE_9__.default.getCompanyList.then is not a function

阅读 5.9k
2 个回答

getCompanyList是方法,调用不正确

api.getCompanyList()

你少了括号

api.getCompanyList().then(res=>{
 ....
})
推荐问题