mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
f26a801775
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Roe <daniel@roe.dev>
1.2 KiB
1.2 KiB
title | description |
---|---|
Runtime Config | Nuxt provides a runtime config API to expose configuration and secrets within your application. |
::callout{color="amber" icon="i-ph-warning-duotone"}
When using runtimeConfig
option, nitro must have been configured.
::
Update Runtime Config
Nuxt 3 approaches runtime config differently than Nuxt 2, using a new combined runtimeConfig
option.
First, you'll need to combine your publicRuntimeConfig
and privateRuntimeConfig
properties into a new one called runtimeConfig
, with the public config within a key called public
.
// nuxt.config.js
- privateRuntimeConfig: {
- apiKey: process.env.NUXT_API_KEY || 'super-secret-key'
- },
- publicRuntimeConfig: {
- websiteURL: 'https://public-data.com'
- }
+ runtimeConfig: {
+ apiKey: process.env.NUXT_API_KEY || 'super-secret-key',
+ public: {
+ websiteURL: 'https://public-data.com'
+ }
+ }
This also means that when you need to access public runtime config, it's behind a property called public
. If you use public runtime config, you'll need to update your code.
// MyWidget.vue
- <div>Website: {{ $config.websiteURL }}</div>
+ <div>Website: {{ $config.public.websiteURL }}</div>