axios二次封装
import axios from 'axios'
import { Indicator, MessageBox } from 'mint-ui'
const ajax = axios.create({
// baseURL: isDev ? 'http://rap2api.taobao.org/app/mock/25656' : '其他地址',
})
ajax.interceptors.request.use((config) => {
Indicator.open({
text: '加载中...',
spinnerType: 'fading-circle'
})
return config
})
ajax.interceptors.response.use((resp) => {
let ret = null
if (resp.status === 200) {
ret = Promise.resolve(resp.data)
} else {
const errMessage = resp.status.errMessage || '未知'
MessageBox({
title: '出错了',
message: errMessage,
confirmButtonText: 'ok',
showCancelButton: true
})
}
Indicator.close()
return ret
})
export default ajax
export const getJpHome = () => ajax.get('/jp/api/getIndexNavSkip?page=1&zy_ids=p8_c4_l4&app_name=zhe&catname=newest_zhe')
export const getJXZC = () => ajax.get('/jp/api/getGoods?page=1&zy_ids=p8_c4_l4&app_name=zhe&catname=tab_hpzc&flag=tab_hpzc')
export const getJXDP = () => ajax.get('/jp/api/getGoods?page=1&zy_ids=p8_c4_l4&app_name=zhe&catname=tab_hpdp&flag=tab_hpdp')
export const getCategory = () => {
const now = new Date().getTime()
return ajax.get(`http://rap2api.taobao.org/app/mock/25656/v2/jp/sort?_t=${now}`)
}