我有一个简单的管理应用程序,它通过表单创建新业务并将它们添加到表中。我已经创建了添加和删除条目的方法,但不确定如何继续创建更新方法。内容是 contenteditable,我想在单击保存按钮时保存它。请查看我的 CodePen:http ://codepen.io/Auzy/pen/177244afc7cb487905b927dd3a32ae61为此,我使用 VueJS 和 Vuefire 以下方式(请原谅 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>
和 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')
}
}
})