update 优化get请求传参,允许根据接口获取url

This commit is contained in:
2021-05-14 09:33:33 +08:00
parent 192e42fde1
commit c08128cc0f

View File

@@ -101,9 +101,23 @@ for (let key in urls) {
if (method === 'post') {
return initInstance(options).post(url, params)
} else {
return initInstance(options).get(url, {
params
let _params = [],
_url = url
Object.keys(params).forEach(key => {
const value = params[key]
switch (value.constructor) {
case Array:
_params.push(...value.map(p => `${key}=${p}`))
break
default:
_params.push(`${key}=${value}`)
break
}
})
if (_params.length) {
_url += '?' + _params.join('&')
}
return initInstance(options).get(_url)
}
}
@@ -145,7 +159,8 @@ for (let key in urls) {
})
}
api[key].prototype.name = key
api[key].url = axios.defaults.baseURL + url
api[key].key = key
}
/**