mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +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`**.
|
||||
::
|
||||
|
||||
### 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
|
||||
|
||||
Within the API routes, you can access runtime config by directly importing from virtual `#config`.
|
||||
|
Loading…
Reference in New Issue
Block a user