From a569d169006872f1543b4abaad22097803e189a4 Mon Sep 17 00:00:00 2001 From: notRyan Date: Tue, 25 Jan 2022 13:04:22 +0100 Subject: [PATCH] docs: add example of `useRuntimeConfig()` within a plugin (#2900) --- docs/content/3.docs/1.usage/5.runtime-config.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/content/3.docs/1.usage/5.runtime-config.md b/docs/content/3.docs/1.usage/5.runtime-config.md index 565f42b553..25bf75954e 100644 --- a/docs/content/3.docs/1.usage/5.runtime-config.md +++ b/docs/content/3.docs/1.usage/5.runtime-config.md @@ -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`.