接口返回的不同数据处理
接口返回的不同数据处理
返回:图片
export function valiCodeApply( userPhone ) { return request({ url: '/credit/validateCode', method: 'post', responseType:'blob', data:qs.stringify({ "userPhone":userPhone, // 手机号码 }), }) } valiCodeApply(this.phone.replace(/\s*/g,"")).then(res => { // console.log(res,'图形验证码') this.validateImg = window.URL.createObjectURL(res.data) }).catch(err => { console.log(err) })
返回:数据数组 通过createTime(时间)以月为分割点生成新的数据
_this.profitList = res.data.data.content _this.profit = [] var map = {}; for(var i = 0; i < _this.profitList.length; i++){ var ai = _this.profitList[i]; // console.log(_this.profitList[i].createTime.substring(0,7)) // createTime: "2019-07-02T01:32:01.000+0000" 时间样例 if(!map[ai.createTime.substring(0,7)]){ _this.profit.push({ createTime: ai.createTime.substring(0,7), data: [ai] }); map[ai.createTime.substring(0,7)] = ai; } else { for(var j = 0; j < _this.profit.length; j++){ var dj = _this.profit[j]; if(dj.createTime.substring(0,7) == ai.createTime.substring(0,7)){ dj.data.push(ai); break; } } } }