Skip to content

Commit b312e21

Browse files
Niall O'Brienposva
authored andcommitted
Adds a complete example (#32)
* Adds a complete example Adds a complete example showing how to save user input to Firebase. * Update README.md
1 parent 6dae0b4 commit b312e21

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,34 @@ vm.$bindAsObject('user', myFirebaseRef.child('user'))
8282
vm.$bindAsArray('items', myFirebaseRef.child('items').limitToLast(25))
8383
```
8484

85+
To save user-input to your Firebase database, simply push the data onto `this.$firebaseRefs.items` (instead of `this.items`) within a Vue method to automatically sync with Firebase.
86+
For example, in your template you could add something simple like
87+
```html
88+
<input v-model="item" placeholder="Add an item"/>
89+
<button @click="addItem">Add item</button>
90+
91+
```
92+
And within your Vue component
93+
```js
94+
export default {
95+
data () {
96+
return {
97+
item: ''
98+
}
99+
},
100+
firebase: {
101+
items: db.ref('items')
102+
},
103+
methods: {
104+
addItem () {
105+
this.$firebaseRefs.items.push({
106+
name: this.item
107+
})
108+
}
109+
}
110+
}
111+
112+
```
85113
## Data Normalization
86114

87115
### Array Bindings

0 commit comments

Comments
 (0)