前端页面接口文件统一管理,适用于vue、uniapp、react

前端页面在根目录下的文件夹pages=》index=》index.vue

接口统一在根目录下的文件夹api=》index(自己模块归类文件夹里)=》...

前端页面代码:

引入统一的接口文件

import { getAds, getData } from '../../api/index/index.js'

 

使用如下:
getData().then(res => {
  if (res.code == 200) {
                       
 } else {}
  }).catch(error => {
       
  })

 

前端接口统一代码:

import http from '@/api/http.js'
import config from '@/config/index.js'
 
export function getAds(params) {
    return http.get(`****/ads`, params);
}
export function getData (data) {
    return http.post('***/getData',data);
}

 

posted @ 2021-01-03 11:21  james_liang  阅读(602)  评论(0编辑  收藏  举报