axios请求拦截
import axios from "axios";
let isProd = process.env.NODE_ENV === 'production';
let baseURL;
isProd = true;
if (isProd) {
baseURL = "http://huruqing.cn:3006";
} else {
baseURL = "http://localhost:3006";
}
const service = axios.create({
baseURL,
timeout: 10 * 60 * 1000,
});
//4. 请求拦截
service.interceptors.request.use(
(config) => {
// do something
return config;
},
(err) => {
return Promise.reject(err);
}
);
service.interceptors.response.use(
(res) => {
const data = res.data;
if (data.code != 666) {
return Promise.reject(data.msg);
}
return data;
},
(err) => {
return Promise.reject(err);
}
);
export default service;
接口配置
import $axios from './request';
//browse(浏览)模块
export const $browseAdd = (data={})=> {
return $axios.post('/browse/add',data);
}
export const $browseList = (params={})=> {
return $axios.get('/browse/list',{params});
}
export const $browseDetail = (params={})=> {
return $axios.get('/browse/detail',{params});
}
export const $browseDel = (data={})=> {
return $axios.post('/browse/del',data);
}
//city(城市)模块
export const $cityList = (params={})=> {
return $axios.get('/city/list',{params});
}
export const $cityDetail = (params={})=> {
return $axios.get('/city/detail',{params});
}
export const $cityEdit = (data={})=> {
return $axios.post('/city/edit',data);
}
//date(日期)模块
export const $dateAdd = (data={})=> {
return $axios.post('/date/add',data);
}
export const $dateAll = (params={})=> {
return $axios.get('/date/all',{params});
}
export const $dateDetail = (params={})=> {
return $axios.get('/date/detail',{params});
}
//demand(需求)模块
export const $demandAdd = (data={})=> {
return $axios.post('/demand/add',data);
}
export const $demandAll = (params={})=> {
return $axios.get('/demand/all',{params});
}
//destination(目的地)模块
export const $destinationAdd = (data={})=> {
return $axios.post('/destination/add',data);
}
export const $destinationList = (params={})=> {
return $axios.get('/destination/list',{params});
}
export const $destinationDetail = (params={})=> {
return $axios.get('/destination/detail',{params});
}
export const $destinationEdit = (data={})=> {
return $axios.post('/destination/edit',data);
}
//discover(发现)模块
export const $discoverList = (params={})=> {
return $axios.get('/discover/list',{params});
}
export const $discoverDetail = (params={})=> {
return $axios.get('/discover/detail',{params});
}
//house(房源)模块
export const $houseIntroduction = (params={})=> {
return $axios.get('/house/introduction',{params});
}
export const $houseComment = (params={})=> {
return $axios.get('/house/comment',{params});
}
export const $houseScene = (params={})=> {
return $axios.get('/house/scene',{params});
}
export const $houseCity = (params={})=> {
return $axios.get('/house/city',{params});
}
export const $houseAround = (data={})=> {
return $axios.post('/house/around',data);
}
export const $houseAll = (params={})=> {
return $axios.get('/house/all',{params});
}
export const $houseList = (params={})=> {
return $axios.get('/house/list',{params});
}
export const $houseRecommend = (params={})=> {
return $axios.get('/house/recommend',{params});
}
export const $houseDetail = (params={})=> {
return $axios.get('/house/detail',{params});
}
//love(收藏)模块
export const $loveChange = (params={})=> {
return $axios.get('/love/change',{params});
}
export const $loveAll = (params={})=> {
return $axios.get('/love/all',{params});
}
export const $loveList = (params={})=> {
return $axios.get('/love/list',{params});
}
export const $loveDetail = (params={})=> {
return $axios.get('/love/detail',{params});
}
//order(订单)模块
export const $orderAdd = (data={})=> {
return $axios.post('/order/add',data);
}
export const $orderList = (params={})=> {
return $axios.get('/order/list',{params});
}
export const $orderDetail = (params={})=> {
return $axios.get('/order/detail',{params});
}
export const $orderEdit = (data={})=> {
return $axios.post('/order/edit',data);
}
//user(用户)模块
export const $userList = (params={})=> {
return $axios.get('/user/list',{params});
}
export const $userDetail = (params={})=> {
return $axios.get('/user/detail',{params});
}
export const $userGetSmsCode = (params={})=> {
return $axios.get('/user/getSmsCode',{params});
}
export const $userLoginBySmsCode = (params={})=> {
return $axios.get('/user/loginBySmsCode',{params});
}
//villa(别墅)模块
export const $villaAdd = (data={})=> {
return $axios.post('/villa/add',data);
}
export const $villaAll = (params={})=> {
return $axios.get('/villa/all',{params});
}
export const $villaTypes = (params={})=> {
return $axios.get('/villa/types',{params});
}
export const $villaList = (params={})=> {
return $axios.get('/villa/list',{params});
}
export const $villaDetail = (params={})=> {
return $axios.get('/villa/detail',{params});
}
export const $villaEdit = (data={})=> {
return $axios.post('/villa/edit',data);
}