I have a simple admin app that creates new businesses via form and adds them to a table. I have created methods to add and delete entries, but am not sure how to proceed creating an update method. The content is contenteditable and I want to save that on save button click. Please see my CodePen: http://codepen.io/Auzy/pen/177244afc7cb487905b927dd3a32ae61 To do this I use VueJS and Vuefire the following way (pardon the Bootstrap):
<!-- Table -->
<table class="table table-striped">
<tr>
<th>Business Name</th>
<th>Vanity URL</th>
<th>Story</th>
<th>Actions</th>
</tr>
<tr v-for="post in posts" :key="post['.key']">
<td contenteditable v-model="newPost.title">{{post.title}}</td>
<td>{{post.content}}</td>
<td>{{post.story}}</td>
<td>
<button v-on:click="removePost(post)" type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</button>
<button v-on:click="removePost(post)" type="button" class="btn btn-danger btn-sm"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete</button>
</td>
</tr>
</table>
</div>
</div>
And JS:
// Setup Firebase
let config = {
...firebase stuff...
}
let firebaseapp = firebase.initializeApp(config);
let db = firebaseapp.database();
let postsRef = db.ref('blog/posts')
// create Vue app
var app = new Vue({
// element to mount to
el: '#app',
// initial data
data: {
newPost: {
title: '',
content: '',
story: ''
}
},
// firebase binding
// https://github.com/vuejs/vuefire
firebase: {
posts: postsRef
},
// methods
methods: {
addPost: function () {
postsRef.push(this.newPost);
this.newPost.title = '';
this.newPost.content = '';
this.newPost.story = '';
},
removePost: function (post) {
postsRef.child(post['.key']).remove()
toastr.success('Business removed successfully')
}
}
})