目录结构如下:
axios实例有
/**
* Axios 实例, ajax请求底层方法
* 官方文档 [https://github.com/axios/axios]{@link https://github.com/axios/axios}
* @module utils/axios
*/
import axios from 'axios'
// axios.defaults.withCredentials = true
/**
* 取消请求
* @type {CancelTokenSource}
* @example
*
* import {source} from '@/utils/axios'
* source.cancel('描述文字....')
*/
export const source = axios.CancelToken.source()
/**
* Axios实例化参数选项对象
* @const
* @type {object}
* @property {object} headers 请求头对象对象,默认:null
* @property {number} timeout 超时时间,默认:0, 不限制
* @property {boolean} withCredentials 是否带上验证信息, 默认:true
* @property {number} maxContentLength 限制最大发送内容长度,默认:-1 不限制
*/
const config = {
headers: {
'Content-Type': 'application/json;charset=UTF-8'
},
baseURL:'https://www.abc.com/api',
timeout: 0,
responseType: 'json',
maxContentLength: -1,
cancelToken: source.token,
withCredentials:true
}
const service = axios.create(config)
/**
* Axios 实例
* @example
*
* // 基础用法
* import axios from '@/utils/axios'
* axios({
* method: 'post',
* url: '/user/123',
* data: {
* firstName: 'Fred',
* lastName: 'Flintstone'
* }
* })
*
* @example
*
* // 实例方法
* axios.request(config)
* axios.get(url[, config])
* axios.delete(url[, config])
* axios.head(url[, config])
* axios.options(url[, config])
* axios.post(url[, data[, config]])
* axios.put(url[, data[, config]])
* axios.patch(url[, data[, config]])
*
* @example config
* {
* // `url` is the server URL that will be used for the request
* url: '/user',
*
* // `method` is the request method to be used when making the request
* method: 'get', // default
*
* // `baseURL` will be prepended to `url` unless `url` is absolute.
* // It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
* // to methods of that instance.
* baseURL: 'https://some-domain.com/api/',
* // `transformRequest` allows changes to the request data before it is sent to the server
* // This is only applicable for request methods 'PUT', 'POST', and 'PATCH'
* // The last function in the array must return a string or an instance of Buffer, ArrayBuffer,
*