mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 15:42:09 +00:00
docs(plugins): add note about composable usage (#6744)
Co-authored-by: Pooya Parsa <pooya@pi0.io>
This commit is contained in:
parent
cf5ba86747
commit
746196f1b0
@ -39,6 +39,26 @@ export default defineNuxtPlugin(nuxtApp => {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Using Composables Within Plugins
|
||||||
|
|
||||||
|
You can use [composables](/guide/directory-structure/composables) within Nuxt plugins:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export default defineNuxtPlugin((NuxtApp) => {
|
||||||
|
const foo = useFoo()
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
However, keep in mind there are some limitations and differences:
|
||||||
|
|
||||||
|
**If a composable depends on another plugin registered later, it might not work.**
|
||||||
|
|
||||||
|
**Reason:** Plugins are called in order sequencially and before everything else. You might use a composable that dependants on another plugin which is not called yet.
|
||||||
|
|
||||||
|
**If a composable depends on the Vue.js lifecycle, it won't work.**
|
||||||
|
|
||||||
|
**Reason:** Normally, Vue.js composables are bound to the current component instance while plugins are only bound to `nuxtApp` instance.
|
||||||
|
|
||||||
## Automatically Providing Helpers
|
## Automatically Providing Helpers
|
||||||
|
|
||||||
If you would like to provide a helper on the `NuxtApp` instance, return it from the plugin under a `provide` key. For example:
|
If you would like to provide a helper on the `NuxtApp` instance, return it from the plugin under a `provide` key. For example:
|
||||||
|
Loading…
Reference in New Issue
Block a user