mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-18 06:31:27 +00:00
docs: add example of useRuntimeConfig()
within a plugin (#2900)
This commit is contained in:
parent
29fa0c991b
commit
a569d16900
@ -77,6 +77,21 @@ const config = useRuntimeConfig()
|
|||||||
**`useRuntimeConfig` only works during `setup` or `Lifecycle Hooks`**.
|
**`useRuntimeConfig` only works during `setup` or `Lifecycle Hooks`**.
|
||||||
::
|
::
|
||||||
|
|
||||||
|
### Plugins
|
||||||
|
|
||||||
|
If you want to use the runtime confg within any (custom) plugin, you can use `useRuntimeConfig()` inside of your `defineNuxtPlugin` function.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
```ts
|
||||||
|
export default defineNuxtPlugin((nuxtApp) => {
|
||||||
|
const config = useRuntimeConfig();
|
||||||
|
|
||||||
|
const url = process.server ? config.serverUrl : config.clientUrl;
|
||||||
|
|
||||||
|
// Do something with url & isServer.
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
### API routes
|
### API routes
|
||||||
|
|
||||||
Within the API routes, you can access runtime config by directly importing from virtual `#config`.
|
Within the API routes, you can access runtime config by directly importing from virtual `#config`.
|
||||||
|
Loading…
Reference in New Issue
Block a user