Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.

Commit 746196f

Browse files
HomWangpi0
andauthored
docs(plugins): add note about composable usage (#6744)
Co-authored-by: Pooya Parsa <[email protected]>
1 parent cf5ba86 commit 746196f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/content/2.guide/3.directory-structure/11.plugins.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ export default defineNuxtPlugin(nuxtApp => {
3939
})
4040
```
4141

42+
## Using Composables Within Plugins
43+
44+
You can use [composables](/guide/directory-structure/composables) within Nuxt plugins:
45+
46+
```ts
47+
export default defineNuxtPlugin((NuxtApp) => {
48+
const foo = useFoo()
49+
})
50+
```
51+
52+
However, keep in mind there are some limitations and differences:
53+
54+
**If a composable depends on another plugin registered later, it might not work.**
55+
56+
**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.
57+
58+
**If a composable depends on the Vue.js lifecycle, it won't work.**
59+
60+
**Reason:** Normally, Vue.js composables are bound to the current component instance while plugins are only bound to `nuxtApp` instance.
61+
4262
## Automatically Providing Helpers
4363

4464
If you would like to provide a helper on the `NuxtApp` instance, return it from the plugin under a `provide` key. For example:

0 commit comments

Comments
 (0)