I'm working through the Vue tutorial at https://medium.com/codingthesmartway-com-blog/vue-js-2-firebase-e4b2479e35a8. I can post new data to firebase but I'm not getting any returned data.
I see this error in the console:
vue.esm.js?efeb:578
[Vue warn]: Property or method "books" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
The relevant blocks are below. Here's the template loop for displaying the retrieved data:
<tr v-for="(book, key) in books" v-bind:key="key">
<td>
{{book.title}}
</td>
</tr>
In the script section:
import Firebase from 'firebase'
let config = {
apiKey: "...",
authDomain: "...",
databaseURL: "https://...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "..."
};
let app = Firebase.initializeApp(config)
let db = app.database()
let booksRef = db.ref('books/')
/* was
export default {
name: 'app',
firebase: {
books: booksRef
},
*/
export default {
name: 'app',
firebase: function () {
return {
books: db.ref('books/')
}
},
data() {
return {
newBook: {
title: '',
author: '',
}
}
},
methods: {
addBook: function() {
// code here
},
removeBook: function(book) {
// code here
}
}
}
Any advice would be appreciated!