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}`) }
