Dependent Request
Sometimes, you may encounter situations where network requests depend on each other, such as the request parameters of request B depending on the return result of request A. In this case, you can use ready
to handle these dependencies.
Automatic mode
When manual=false
, each time ready
changes from false
to true
, a request will be automatically sent, and the parameter options.defaultParams
will be included.
Manual mode
When manual=true
, a request cannot be initiated as long as ready
is false
.
In addition to supporting the input of a Ref<boolean>
type value, ready
also supports passing in a function that returns a boolean value () => boolean
, similar to the usage of Vue's watch
.
const props = defineProps({
ready: Boolean,
});
useRequest(getUser, {
ready: () => props.ready,
});