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}`)
}
request 请求节流
最新推荐文章于 2024-08-14 15:45:18 发布