1、在api文件夹中建立index.js文件
引入axios二次封装的文件
import requests from "./request";
对外暴露一个函数,只要外部调用这个函数,就向服务器发起ajax请求,例如:
export const reqCategoryList=()=>requests({url:'/product/getBaseCategoryListe',method:'get'});
2、在入口文件中统一接收api文件夹里面全部请求函数,统一引入
import * as API from '@/api';
注册为全局事件总线$bus配置
beforeCreate() {
Vue.prototype.$API = API;
},