首先,我做的是后台管理系统,大多是需要进入页面就获取数据并渲染,而这个数据中需要拿到图片的一个字段,调用接口传参,返回图片的编码,但是我现在调接口之后返回res是undefind
created 里面调用获取数据,进行图片处理:
QueryAppraisal(reqBody).then((res) => {
if (!res.result) {
that.dataList = [];
that.totalPage = 0;
return;
}
let data = res["data"] || {};
that.totalPage = data["totalCount"] || 0;
that.dataList = data["list"] || [];
// 获取图片处理
that.getImg();
})
.catch((err) => {
that.dataList = [];
that.totalPage = 0;
this.$message.error(err);
});
/**
* 获取图片
*/
getImg(){
let that = this
if(that.dataList == "" || that.dataList == null){
return
}else {
let imgArr = []
that.dataList.map(function(item,index){
return imgArr = item['otherInfo']['imageInfo']
})
let fileCode = ""
imgArr.map(function(item,index){
return fileCode = item.imageCode
})
let reqBody = {
fileCode:fileCode,
isShowImage:true
}
GetFile(reqBody).then((res) =>{
console.log(res)
})
}
},
运行结果: undefined
我是在重构之前的代码,接口封装 那边写的没啥问题,其他接口也能获取,这个接口postman调了能获取图片,我认为有问题顶多是传参问题
network里看看接口状态码? 和response里返回了什么
res 是 undefined? 你确定你没写错吗?
如果是,看看 QueryAppraisal 这个方法是否 return 了内容
可能这个接口返回的数据格式和其它接口不一样,所以你封装promise中resolve中传的值没取到,也就是res没取到
站长接口测试工具测一下呗