uni-request
Version:
基于Promise封装uni-app的request方法,h5和小程序均可使用
29 lines (24 loc) • 527 B
JavaScript
export default class InterceptorManager{
constructor(){
this.handlers = [];
}
use(fulfilled, rejected){
this.handlers.push({
fulfilled,
rejected
});
return this.handlers.length - 1;
}
eject(id){
if( this.handlers[id] ){
this.handlers[id] = null;
}
}
forEach(fn){
this.handlers.forEach(e =>{
if(e !== null ){
fn(e)
}
})
}
}