使用AbortController中止Fetch请求
let controller; function fetchVideo() { controller = new AbortController(); const signal = controller.signal; fetch(url, { signal }) .then((response) => { console.log('Download complete', response); }) .catch((err) => { console.error(`Download error: ${err.message}`); }); } const onInputChange= () => { if (controller) controller.abort(); }
const onFilterClick= () => {
if (controller) controller.abort();
}