You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can access all of the Firebase services within components with the different composables provided by VueFire:
4
+
5
+
```vue
6
+
<script setup>
7
+
import {
8
+
useFirebaseApp,
9
+
useAuth,
10
+
useDatabase,
11
+
useFirestore,
12
+
useStorage,
13
+
} from 'vuefire'
14
+
15
+
const firebaseApp = useFirebaseApp()
16
+
const auth = useAuth()
17
+
const database = useDatabase()
18
+
const firestore = useFirestore()
19
+
const storage = useStorage()
20
+
</script>
21
+
```
22
+
23
+
As [all composables](https://vuejs.org/guide/reusability/composables.html), these must be called within the _setup_ of a component. However, you can call these specific Firebase Services composables anywhere in your application as long as you pass the **Firebase App name as the parameter**.
24
+
25
+
```ts
26
+
27
+
```
28
+
29
+
::: tip
30
+
The Firebase Name parameter is only needed when using the composable outside of _setup_ and one of these condition are met:
31
+
32
+
- You are doing SSR
33
+
- You have multiple Firebase Apps
34
+
35
+
**Omit the name in all other scenarios**, it's just not needed.
Copy file name to clipboardExpand all lines: docs/guide/getting-started.md
+32-7
Original file line number
Diff line number
Diff line change
@@ -20,24 +20,49 @@ VueFire requires Firebase JS SDK >= 9 but **is compatible with Vue 2 and Vue 3**
20
20
21
21
## Usage
22
22
23
-
VueFire expects you to use the existing APIs from Firebase as much as possible. It doesn't expose any configs to initialize your app or get the database/firestore instances. You should follow the official Firebase documentation for that. We do have [some recommendations](#TODO) for a Vue project and [a Nuxt module](./nuxt.md) to help you get started.
23
+
VueFire expects you to use the existing APIs from Firebase as much as possible. It doesn't expose any configs to initialize your app or get the database/firestore instances. You should follow the official Firebase documentation for that. We do have [a Nuxt module](./nuxt.md)that makes it even easier to use VueFire with Nuxt.
24
24
25
25
Most of the time, you should gather collection references in one of your files and export them but **to keep examples short, we will always create the database references whenever necessary** instead of gathering them in one place. We will also consider that we have access to some globals (you usually import them from the file where you initialize your Firebase app):
// here we can export reusable database references
59
+
exportconsttodosRef=collection(db, 'todos')
39
60
```
40
61
62
+
</FirebaseExample>
63
+
64
+
Note exporting Database and Firestore isn't necessary as you can always accessing Firebase services within your components with [`useFirebaseApp()` and other composables](./firebase-composables.md).
65
+
41
66
::: tip
42
67
Note that we will refer to `database` and `firestore` as `db` in examples where only one of them is used.
43
68
:::
@@ -67,7 +92,7 @@ app
67
92
app.mount('#app')
68
93
```
69
94
70
-
This will give you access to some convenient composables like `useFirebaseApp()`, `useFirestore()` and `useDatabase()` in your components:
95
+
This will give you access to some [convenient composables](./firebase-composables.md) like `useFirebaseApp()`, `useFirestore()` and `useDatabase()` in your components:
71
96
72
97
```vue
73
98
<script setup>
@@ -171,7 +196,7 @@ If you want to change the data, you should use the Firebase API (e.g. `setDoc()`
171
196
172
197
### Options API
173
198
174
-
TODO: complete this section. The composition API is the recommended way to use VueFire at the moment because its API is more stable and it's easier to use with TypeScript.
199
+
The composition API is the recommended way to use VueFire because its API is more flexible and it's easier to use with TypeScript.
175
200
176
201
VueFire can also be used with the Options API, while less flexible, it's still a valid way to use VueFire. First, you need to install the options plugin:
Copy file name to clipboardExpand all lines: docs/guide/realtime-data.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -300,7 +300,7 @@ Note this is only a type annotation, it does not perform any runtime validation.
300
300
The recommended Firebase approach is to use the `withConverter()` for Firestore:
301
301
302
302
::: info
303
-
`.withConverter()` is a Firestore feature that doesn't have an equivalent in Database but you can use VueFire's [`serialize()` option](#TODO:globaloptions when installing plugin) instead.
303
+
`.withConverter()` is a Firestore feature that doesn't have an equivalent in Database but you can use VueFire's [`serialize()` option](./global-options.md#firestore-and-database-global-options) instead.
0 commit comments