Giter VIP home page Giter VIP logo

Comments (8)

bloor avatar bloor commented on August 10, 2024 4

A request-abort is much needed, especially for React/Vue projects.
Please provide a solution.

from ofetch.

xuxucode avatar xuxucode commented on August 10, 2024 4

It does support AbortController. $fetch accepts options whatever you passed in: https://github.com/unjs/ohmyfetch/blob/main/src/fetch.ts#L127.

For example:

  const controller = new AbortController();
  const signal = controller.signal;
  $fetch(url, { signal });

  controller.abort();

from ofetch.

CaptainFalcon92 avatar CaptainFalcon92 commented on August 10, 2024 2

In case it could help as inspiration, vueuse provides an abort() function from its version of useFetch()
https://github.com/vueuse/vueuse/blob/main/packages/core/useFetch/index.ts#L359
https://vueuse.org/core/useFetch/#aborting-a-request

The AbortController instance is created internally.

Using ofetch through Nuxt, i mostly use the built-in useFetch composables - not the vueuse one - thus not enjoying this easy-cancellable wizardry. Still it looks like the implementation could be borrowed.

from ofetch.

MichaelGitArt avatar MichaelGitArt commented on August 10, 2024

😶

from ofetch.

bf avatar bf commented on August 10, 2024

AbortController already works like @xuxucode has posted. I tried it. I think we can close this!

from ofetch.

pi0 avatar pi0 commented on August 10, 2024

Indeed. AbortController is supported univerally. I was keeping issue open if we can make a better shortcut syntax for ofetch for canceling requests..

from ofetch.

pi0 avatar pi0 commented on August 10, 2024

We expose an auto polyfilled version of AbortController with #268

from ofetch.

MickL avatar MickL commented on August 10, 2024

In case it could help as inspiration, vueuse provides an abort() function from its version of useFetch() https://github.com/vueuse/vueuse/blob/main/packages/core/useFetch/index.ts#L359 https://vueuse.org/core/useFetch/#aborting-a-request

I would also prefer to have a simple abort() function

from ofetch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.