tuoheng_virtualAirPlan_web/src/utils/request/request.js

32 lines
920 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import instance from './index'
/**
* @param {String} method 请求的方法get、post、delete、put
* @param {String} url 请求的url:
* @param {Object} data 请求的参数
* @param {Object} config 请求的配置
* @returns {Promise} 返回一个promise对象其实就相当于axios请求数据的返回值
*/
export const request = ({ method, url, data, config }) => {
//把大写转换成小写
method = method.toLowerCase()
if (method == 'post') {
return instance.post(url, data, { ...config })
} else if (method == 'get') {
return instance.get(url, {
params: data,
...config,
})
} else if (method == 'delete') {
return instance.delete(url, {
params: data,
...config,
})
} else if (method == 'put') {
return instance.put(url, data, { ...config })
} else {
console.error('未知的method' + method)
return false
}
}