简体   繁体   English

多个获取按钮和 AbortController

[英]Multiple fetch buttons and AbortController

I'm new to Svelte and learning it for self-education.我是 Svelte 的新手,学习它是为了自学。
I'm trying to implement very basic scenario:我正在尝试实现非常基本的场景:
there are multiple buttons on the page, each button fetches some data and displays result in the same area.页面上有多个按钮,每个按钮获取一些数据并在同一区域显示结果。
To make sure that due to the different network response timings later result will not be overwritten by old request I want to abort all previous fetches.为了确保由于不同的网络响应时间,以后的结果不会被旧请求覆盖,我想中止所有以前的提取。
Here is the REPL I've made so far: https://svelte.dev/repl/c763e1814da740f186620d75ad1fa42f?version=3.38.2这是我到目前为止所做的 REPL: https://svelte.dev/repl/c763e1814da740f186620d75ad1fa42f?version=3.38.2
Question: why request aborted in advance and how to correct this?问题:为什么请求提前中止以及如何更正?

(Any advises how to make my Svelte code styling better will be much appreciated, I suspect this logic can be implemented in much better/efficient way) (任何建议如何使我的 Svelte 代码样式更好,将不胜感激,我怀疑这个逻辑可以以更好/有效的方式实现)

It's the AbortController.它是 AbortController。 Once abort() is called it stays in the aborted state.一旦 abort() 被调用,它就会停留在中止的 state 中。 I looked for some references but couldn't find any documentation that states this explicitly.我查找了一些参考资料,但找不到任何明确说明这一点的文档。 However, a bit of trial and error seems to prove this.然而,一些试验和错误似乎证明了这一点。 You need to create a new AbortController after calling abort().您需要在调用 abort() 后创建一个新的 AbortController。

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

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