如何在VueFire中创建动态引用? [英] How to create dynamic references in VueFire?
本文介绍了如何在VueFire中创建动态引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试动态创建引用:
I'm trying to create refs dynamically:
我的第一个ref之所以有效是因为它是经过硬编码的,而第二个ref却没有,显然是因为它是动态的:
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?
推荐答案
我使用在
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))
}
如果您已经有了db.ref绑定,则可能需要 vm.$ unbind
,但是我还没有这样做.
If you've already got a db.ref binding you might have to vm.$unbind
but I haven't had to do that yet.
这篇关于如何在VueFire中创建动态引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文