angular.js - angular中$http如何将请求成功后得到的数据做一层过滤?
本文介绍了angular.js - angular中$http如何将请求成功后得到的数据做一层过滤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
如图所示。后端真正返回给我的数据实在第二层data里面。
我应该如何在全局做一层数据处理?在哪里做比较合适?
解决方案
angular.module('my', [])
.config(function ($httpProvider) {
$httpProvider.interceptors.push(function () {
return {
response: function (response) {
if (200 === response.data.code) {
response.data = response.data.data;
}
return response;
}
}
});
})
这篇关于angular.js - angular中$http如何将请求成功后得到的数据做一层过滤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文