0
Firebase JSONデータベースで使用している単純なVueJSアプリがあります。私は、矢印をクリックしてコメントの「投票」を更新できるようにしたい。 (このウェブサイトがアップフォースを持つ方法と同様)。私の機能が実行されます。しかし、VueモデルはFirebaseを更新しないので、リフレッシュ時に投票数が失われます。私CodePenを参照してください:http://codepen.io/Auzy/pen/evowdd/(通常のHTML/CSSの右上にある矢印をクリックして見て、私はパグやスタイラスを使用することに注意してください。)Vue JS Firebaseデータベースにインクリメントした番号を保存する
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
},
})
'firebase'プロパティは、標準の' Vue'オプションではありません。
は、ここで追加のノートを使用して新しい方法です。 [vuefire](https://github.com/vuejs/vuefire)を使用していますか?もしそうなら、それはどこですか? – Phil
はい、私はVueFireを使用しています。スクリプトタグは、CodePen JS設定のリソースの下にあります。 – Auzy