javascript - 经常看一些框架,如:this.$http.post('',function(res){}),JS怎么实现自定义res这个参数
本文介绍了javascript - 经常看一些框架,如:this.$http.post('',function(res){}),JS怎么实现自定义res这个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
经常看一些框架,如:this.$http.post('',function(res){}),JS怎么实现自定义res这个参数
解决方案
@林岑影
多谢提醒,其实也就是callback的问题,我把你的代码稍微的修改下
var A= A ||{} ;
A.$http={
post:function(cfg,callback){
var callRes={};
for(var index in cfg){
callRes[index]=cfg[index];
}
typeof callback =='function' && callback(callRes)
}
}
var options={
name:'zhu',
age:'99',
sex:'male'
}
A.$http.post(options,function(res){
console.log(res);
})
这篇关于javascript - 经常看一些框架,如:this.$http.post('',function(res){}),JS怎么实现自定义res这个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文