同时请求不同的接口,有时返回相同的数据?

提问 3 635
手机用户_sppl1
手机用户_sppl1 LV2 2021年5月20日 11:53 发表
点击群号免费加入社区交流群:367346704
<p>我在客服端使用Promise.allSettled调用多个接口,全部成功后,我在赋值给本地变量,但是有时不同的接口,返回的数据都是某一个接口的,服务端已经触发各自的接口,并且log打印出来也是各自接口的数据,但返回前端却是错误的,这种情况怎么解决?</p>
收藏(0)  分享
相关标签: springboot
3个回复
  • 站长
    2021年6月12日 16:30
    您提到“log打印出来也是各自接口的数据”说明后端正确返回数据。 您用到Promise异步,说明问题出在您写错了前端异步代码,请修正。 解决方案之一:把前端的请求改成同步方式,代码示例: [pre] querySysMenuButtonTree().then(response => { this.menuButtonTree = response.data this.menuButtonTreeDialogFormVisible = true queryMenuButtonByRoleCode(roleCode).then(menuButtonResponse => { this.$refs.menuButtonTreeRef.setCheckedKeys(menuButtonResponse.data) }) }) [/pre]
    1 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