2017-07-27 73 views
1

Vue.js对于sql程序员来说是一种生活方式的改变,但是到达那里。在这里我使用vuefire按照规格,甚至手动插入我的一个记录,一个字段Firebase DB中的正确密钥来测试它。但看不到任何回报或显示。世界上最简单的vue.js/vuefire/firebase应用程序。但无法读取值

爱知道该怎么做!并填写我的一个价值形式。从那里,我确信天空的极限。谢谢你的帮助。

错误消息:vue.common.js e881:481 [Vue的警告]:错误在安装钩: “的ReferenceError:residentsArray没有定义”

<template> 

    <div class="edit"> 

    <div class="container"> 
     <p style="margin-bottom:10px;font-weight:800;">EDIT RECORD</p><br> 

     <form id="form" v-on:submit.prevent="updateResident"> 

     <fieldset class="form-group"> 
      <label for="first_name">Name</label> 
      <input type="text" class="form-control" id="first_name" name="first_name" v-model="currentResident.name"> 
     </fieldset> 

     <input type="submit" class="btn btn-primary" value="Add New Resident"> 
     </form> 

    </div> 

    </div> 

</template> 

    <script> 

    import firebase from 'firebase' 

    let editConfig = { 
    apiKey: "123456789", 
    authDomain: "myapp.firebaseapp.com", 
    databaseURL: "https://myapp.firebaseio.com", 
    projectId: "my", 
    storageBucket: "myapp.appspot.com", 
    messagingSenderId: "1234567890" 
    }; 

    var firebaseApp = firebase.initializeApp(editConfig, "Edit") 
    var db = firebaseApp.database() 

    let residentsReference = db.ref('residents') 

    export default { 
    name: 'Edit', 
    mounted() { 
     this.currentResident.name = residentsArray.name; 
    }, 
    firebase: { 
     residentsArray: residentsReference.child('-KpzkbA6G4XvEHHMb9H0') 
    }, 
    data() { 
     return { 
     currentResident: { 
      name: '' 
     } 
     } 
    }, 
    methods: { 
     updateResident: function() { 
     // Update record here 
     } 
    } 
    } 
</script> 
+0

如果你的Firebase不是很大/敏感,你有导出Firebase吗? – Bert

+0

嗨,如果我今天不解决它。我会在网上发帖。它肯定是一件简单的事情。类似的问题在这里: https://stackoverflow.com/questions/44995450/vue-js-2-with-firebase-crud-example?rq=1 –

+0

如果你把'console.log(this。$ firebaseRefs.residentsArray )'作为'挂载'的第一行,它是如何记录的? – thanksd

回答

1

你应该在你改变residentsArray.name到钩。

还有一件事:你不需要mounted这个。 我只是做一个computed为此返回this.residentsArray.name。有了这个,你不会有任何绑定问题。

1

从上vuefire Github上读取README,它看起来像你需要通过this.$firebaseRefs指你firebase对象的属性:

mounted() { 
    this.currentResident.name = this.$firebaseRefs.residentsArray.name; 
}, 
+0

给它一个尝试,不工作。错误:“ReferenceError:currentResident没有定义”似乎定义给我。但至少第一个错误消息已经消失。 –

+0

你确定你引用'this.currentResident'而不只是'currentResident'吗? – thanksd

+0

this.currentResident.name = this。$ firebaseRefs.residentsArray.name; console.log(“this.currentResident.name”,this.currentResident.name) > Edit.vue?abe2:130 this.currentResident。名称undefined –

相关问题