简体   繁体   English

使用axios在Vuejs页面中的多个并发请求

[英]Multiple concurrent requests in a Vuejs page using axios

I've created a small component using Vuejs that makes an Ajax request to a passed URL to determine its initial value. 我使用Vuejs创建了一个小组件,该组件向传递的URL发出Ajax请求,以确定其初始值。

When I have a few instances of that component, everything is fine. 当我有该组件的几个实例时,一切都很好。 But if I have more than 5/6 instances, all the requests will be pending forever and I need to restart Valet in order to be able to access any of my local websites. 但是,如果我有5/6个以上的实例,则所有请求将永远待定,我需要重新启动Valet才能访问我的任何本地网站。

Each instance is pointing to a different endpoint in the same domain: 每个实例都指向同一域中的不同端点:

Instance1 => example.com/endpoint1 Instance1 => example.com/endpoint1

Instance2 => example.com/endpoint2 Instance2 => example.com/endpoint2

Instance3 => example.com/endpoint3 Instance3 => example.com/endpoint3

... ...

Each instance doesn't know anything about the others. 每个实例对其他实例一无所知。 They don't communicate between them at all. 他们之间根本不沟通。

Why is this issue happening? 为什么会发生此问题? Is it browser related or is it server related? 它与浏览器相关还是与服务器相关?

(For the backend I'm using Laravel 5.5 running on Valet) (对于后端,我使用的是在Valet上运行的Laravel 5.5)

I believe only you can answer that question doing more logging on both front and back end. 我相信只有您可以回答这个问题,在前端和后端进行更多日志记录。

The solution would be to have a parent component that do the ajax calls and then pass the results to the child components. 解决方案是让一个父组件执行ajax调用,然后将结果传递给子组件。

That way you will be able to limit the number of simultaneous requests and, if needed, add a timeout between requests. 这样,您将能够限制同时请求的数量,并且,如果需要,可以在请求之间添加超时。

You could implement that and play with the variables (number of simultaneous requests and timeout between batches) until it's working but I would advise you instead to understand first where the problem come from and we no have enough information to help you on that. 您可以实现它并使用变量(批处理之间的同时请求数和超时)直到它起作用为止,但是我建议您先了解问题的根源,而我们没有足够的信息来帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM