Javascript 带window.location.reload的递归异步等待回调

Javascript 带window.location.reload的递归异步等待回调,javascript,vue.js,async-await,Javascript,Vue.js,Async Await,我正在等待一些API回调,它返回401响应和注销回调,并重定向到登录页面。但是,它会在注销回调上继续执行window.location.reload,因为API在上一页中被反复调用。我该怎么做才能摆脱这一切 试试看{ //在此处运行首先需要执行的所有操作 等待这个消息。someMethods() 等待这个消息。someMethods() 等待这个消息。someMethods() 等待这个消息。someMethods() 等待这个消息。someMethods() }捕获(错误){ //检查登录会

我正在等待一些API回调,它返回401响应和注销回调,并重定向到登录页面。但是,它会在注销回调上继续执行window.location.reload,因为API在上一页中被反复调用。我该怎么做才能摆脱这一切

试试看{
//在此处运行首先需要执行的所有操作
等待这个消息。someMethods()
等待这个消息。someMethods()
等待这个消息。someMethods()
等待这个消息。someMethods()
等待这个消息。someMethods()
}捕获(错误){
//检查登录会话
const response=Object.assign({},错误)
if(response.response.status==401 | | response.response.status==401){
AuthService.logout()//注销回调
此.$toasted.show('季节已过!。请重新登录'{
位置:'上止点',
时长:2500,
键入:“错误”
})
}

}
您可能需要使用Promise.all

Promise.all([promise1, promise2, promise3]).then(function(values) {
  console.log(values);
});
这是你的例子

try {
        // Run all actions here that needed to be executed at first
        await Promise.all([this.someMethods1() , this.someMethods2() ,this.someMethods3()]) ;

      } catch (error) {
        // Check for login session
        const response = Object.assign({}, error)
        if (response.response.status === 401 || response.response.status === 401) {
          AuthService.logout() //LOGOUT CALLBACK
          this.$toasted.show('Season Expired!. Please Re-Login', {
            position: 'top-center',
            duration: 2500,
            type: 'error'
          })
        }
      }

这样,错误块将只输入一次

重新加载的意义是什么?请注意,
router.push('/login')
在您离开页面后不会执行。也许你的意思是
window.location.replace('/login')
?@Bergi重置vuex stateWell的简单解决方案,看起来是错误的解决方案。我将查找这些解决方案。我有一些这样的箱子,但需要先试试