How to create dynamic references in VueFire?

时光毁灭记忆、已成空白 提交于 2019-12-11 07:14:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!