import axios from ‘axios‘ const isDev = process.env.NODE_ENV === ‘development‘//判断是否为生产环境 const service = axios.create({ baseURL: isDev ? ‘http://rap2.taobao.org:38080/app/mock/251246‘ : ‘‘ }) //请求拦截 service.interceptors.request.use((config) => { config.data = Object.assign({}, config.data, { // authToken: window.localStorage.getItem(‘authToken‘)//本地存贮获取token authToken: ‘fhusfheiuhruehgui‘ }) // console.log(config) return config }) //响应拦截 service.interceptors.response.use((resp) => { if (resp.data.code === 200) { return resp.data.data } else { //全局处理错误 message.error(resp.data.errMsg) } })
使用:
export const getArticalDetail = (id) => { return service.post(`/api/v1/artical/${id}`) }