export const getApi = (params = { cache: true }, time = 2000) => {
// 参数添加cache字段,默认2秒内的请求只发一个
if (params.cache) {
const key = JSON.stringify(params)
let promise = promiseCache.get(key)
if (!promise) {
promise = request.post(`${url}`)
promiseCache.set(key, promise)
}
setTimeout(() => {
promiseCache.delete(key)
}, time)
return promise
}
return request.post(`${url}`)
}