vue项目里封装axios

import axios from 'axios'
import qs from 'qs'
const $ajax = axios.create({
  baseURL: '',
  timeout: 20000
})
const ajaxPost = (api, data = null) => $ajax.post(api, qs.stringify(data, { arrayFormat: 'repeat' }))
const ajaxGet = (api, data = null) => $ajax.get(api, { 
  params: { ...data, '_': new Date().getTime() }, paramsSerializer: function(params) {
    return qs.stringify(params, { arrayFormat: 'repeat' })
  }
})
const jsonPost = (api, data = null) => $ajax.post(api, data, { headers: { 'Content-Type': 'application/json;charset=UTF-8' } })

你可能感兴趣的:(vue项目里封装axios)