前端页面接口文件统一管理,适用于vue、uniapp、react
时间:2021-01-06 12:04:42
收藏:0
阅读:0
前端页面在根目录下的文件夹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);
}
评论(0)