同时请求不同的接口,有时返回相同的数据?
<p>我在客服端使用Promise.allSettled调用多个接口,全部成功后,我在赋值给本地变量,但是有时不同的接口,返回的数据都是某一个接口的,服务端已经触发各自的接口,并且log打印出来也是各自接口的数据,但返回前端却是错误的,这种情况怎么解决?</p>
收藏(0)
分享
相关标签:
-
2021年6月12日 20:10
Promise异步示例:
[pre]
login({ commit }, userInfo) {
const { tenantCode, username, password } = userInfo
return new Promise((resolve, reject) => {
login({ tenantCode: tenantCode.trim(), username: username.trim(), password: password }).then(response => {
commit('SET_TOKEN', response.access_token)
setToken(response.access_token)
registerNewSession().then(response => {
})
resolve()
}).catch(error => {
reject(error)
})
})
}
[/pre]
1
0
-
2021年6月16日 10:49
后端解决办法,修改ResultBuilder返回的方法,使每次都重新加载新的ListResult
修改原因可参考文章:https://blog.csdn.net/nkshuangyuan2012/article/details/80475866
示例更改
public static ListResult<Object> buildListSuccess(String data) {
ListResult<Object> listResult = new ListResult<>();
try {
listResult.setData(data);
listResult.setStatus(HttpStatus.OK.value());
listResult.setMessage(SUCCESS);
} catch (Exception e) {
ResultBuilder.buildListWarn(listResult, e);
}
return listResult;
}
0
0