Global Options

We export the setGlobalOptions() method to give you control over some options and avoid repetition in some of the same options.


E.g., vue-cliopen in new windowviteopen in new window

In the following example, all components that use VueRequest in the current project can read the incoming options. For more configurable global options, please refer to Global Options.

// main.ts
import { setGlobalOptions } from 'vue-request';
// ...
  manual: true,
  // ...

// App.tsx
const { data: user } = useRequest('api/user');
const { data: job } = useRequest('api/job', { manual: false }); // Override global options

Configure via components

In addition to using the API to set the global options, you can also use the RequestConfig component we exported for a more detailed configuration. As shown below, you can pass in different options for different components.

import { defineComponent } from 'vue';
import { RequestConfig } from 'vue-request';
// ...
export default defineComponent({
  name: 'App',
  setup() {
    return () => (
      <div id="app">
        <RequestConfig config={{ loadingDelay: 300 }}>
          <ComponentA />
        <RequestConfig config={{ loadingDelay: 500 }}>
          <ComponentB />


If you use the CDN version, you can set the global configuration in the following ways. We exported the setGlobalOptions() method on the instance of VueRequest

<!-- ... -->
<script src=""></script>
    cacheTime: 12 * 3600,


Options weight: setGlobalOptions < RequestConfig < local options

Last Updated: 6/2/2023, 5:07:34 PM
Contributors: John