fetch 请求终止
- fetch()请求发送以后,如果中途想要取消,需要使用 AbortController 对象
javascript
let controller = new AbortController();
let signal = controller.signal;
fetch(url, {
signal: controller.signal,
});
signal.addEventListener("abort", () => console.log("abort fetch"));
controller.abort(); // 取消
console.log(signal.aborted);