问题
I'm trying to create refs dynamically:
My first ref works because it's hardcoded but the second doesn't, apparently because it's dynamic:
firebase: function(){
return {
categories: db.ref('categories'),
subcategories: db.ref('categories').child(this.addItem.category)
}
}
Does anyone know how to get around this?
回答1:
I created a dynamic db ref by using vm.$bindAsObject
found in the vue-fire docs. I used it in the created hook with a project id, like so:
created () {
this.$bindAsObject('project', db.ref('projects/' + this.$route.params.id))
}
If you've already got a db.ref binding you might have to vm.$unbind
but I haven't had to do that yet.
来源:https://stackoverflow.com/questions/44157125/how-to-create-dynamic-references-in-vuefire