javascript - Vue JS save incremented number to Firebase database -


i have simple vuejs app i'm using firebase json database. want able click arrow update "votes" of comment. (similar how website has upvotes). function runs. vue model never updates firebase , vote count lost on refresh. please reference codepen: http://codepen.io/auzy/pen/evowdd/ (please note use pug , stylus, see normal html/css click arrow in top right.)

js:

// initialize firebase var config = {     databaseurl: "..." }; const firebaseapp = firebase.initializeapp(config); const db = firebaseapp.database(); const commentsref = db.ref('test');  const app = new vue({     el: '#app',     data: {         comments: [],         newcomment: {             name: '',             comment: '',             votes: 0         },     },     methods: {         addcomment() {             commentsref.push(this.newcomment);             this.newcomment.name = '';             this.newcomment.message = '';             this.newcomment.votes = 0;         },         vote: function (votetype, comment) {             if (votetype === "up") {                 comment.votes++             } else if (votetype === "down") {                 if (comment.votes <= -10) {                     return;                 }                  comment.votes--;             }         },     },     firebase: {         comments: commentsref     },  }) 

alright, believe i've figured out. please answer if have better method.

here new method added notes:

incrementvote(comment) {     comment.votes++ //increment vote count     const businesschildkey = comment['.key']; //get key of modified comment     delete comment['.key']; //firebase doesn't know how handle them can use vuefire around that.     this.$firebaserefs.comments.child(businesschildkey).set(comment) //updates firebase record matching key }, 

Comments