docs: add note for usage (#1921)

This commit is contained in:
webfansplz 2021-11-15 21:13:00 +08:00 committed by GitHub
parent 5786949d9b
commit b69ebbbfd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -2,6 +2,10 @@
Nuxt provides `useFetch`, `useLazyFetch`, `useAsyncData` and `useLazyAsyncData` to handle data fetching within your application.
::alert{icon=👉}
**`useFetch`, `useLazyFetch`, `useAsyncData` and `useLazyAsyncData` only works during `setup` or `Lifecycle Hooks`**
::
## `useAsyncData`
Within your pages, components and plugins you can use `useAsyncData` to get access to data that resolves asynchronously.
@ -57,10 +61,6 @@ Within your pages, components and plugins you can use `useFetch` to get universa
This composable provides a convenient wrapper around `useAsyncData` and `$fetch` and automatically generates a key based on url and fetch options and infers API response type.
::alert{icon=👉}
**`useFetch` only works during `setup` or `Lifecycle Hooks`**
::
### Usage
```ts

View File

@ -19,6 +19,10 @@ function useMyComposable () {
Plugins also receive `nuxtApp` as the first argument for convenience. [Read more about plugins.](/docs/directory-structure/plugins)
::alert{icon=👉}
**`useNuxtApp` (on server side) only works during `setup`, inside Nuxt plugins or `Lifecycle Hooks`**
::
## Providing helpers
You can provide helpers to be usable across all composables and application. This usually happens within a nuxt plugin.

View File

@ -73,6 +73,10 @@ const config = useRuntimeConfig()
**🛑 Security note:** Never use example above if `API_AUTH_TOKEN` is a private config. Even if you use `privateRuntimeConfig`, you have to be still careful you do not expose such config to either payload or html!
::alert{icon=👉}
**`useRuntimeConfig` only works during `setup` or `Lifecycle Hooks`**
::
### API routes
Within the API routes, you can access runtime config by directly importing from virtual `#config`.