简体   繁体   English

Vuetify Firebase 数据未显示在数据表中

[英]Vuetify Firebase Data not Displayed in Datatable

I have a problem on my code.我的代码有问题。 I can't display my data to Vuetify Datatable, Although it is enable Read and write on my Firebase Database and the data is loaded into the array object:我无法将我的数据显示到 Vuetify 数据表,尽管它在我的 Firebase 数据库上启用了读写功能,并且数据已加载到数组 object 中:

Anyway here is my code for that, any wrong with my code?无论如何,这是我的代码,我的代码有什么问题吗? Comments are greatly appreciated:非常感谢评论:

<template>
    <div>
      <v-data-table
        :headers= "headers"
        :items= "userdata"
        class="elevation-1"
        hide-default-header
        hide-default-footer
      >
      </v-data-table>
    </div>
  </template>

<script>

import firebase from '@/configFirebase.js'

export default { 
  data: ()=> ({
    headers: [
        {
          text: 'Active Users',
          align: 'start',
          sortable: false,
          value: 'name',
        },
        { text: 'Email', sortable: false, value: 'email' },
        { text: 'Is Admin', sortable: false, value: 'isAdmin'},
      ],
    }),

    methods: {
        aUserData() {
            firebase.db
            .collection('cUsers').get().then((querySnapShot) => {
                this.userdata = []
                querySnapShot.forEach((doc) => {
                    this.userdata.push({
                        name: doc.data().name,
                        email: doc.data().email,
                        isAdmin: doc.data().isAdmin               
                    })
                })
            })      
        },

        getitemcontrols() {
            return `item.isAdmin`;
        },
    },

    mounted() {
        
    },

    created(){
        this.aUserData(); 
    },

    computed: {
        user() {
            return this.$store.getters.user
        },
    }
}
</script>

You need to declare userdata in data block, added notes explaining what changed:您需要在data块中userdata用户数据,添加解释更改内容的注释:

<template>
    <div>
      <v-data-table
        :headers= "headers"
        :items= "userdata"
        class="elevation-1"
        hide-default-header
        hide-default-footer
      >
      </v-data-table>
    </div>
  </template>

<script>

import firebase from '@/configFirebase.js'

export default { 
  data: ()=> ({
    headers: [
        {
          text: 'Active Users',
          align: 'start',
          sortable: false,
          value: 'name',
        },
        { text: 'Email', sortable: false, value: 'email' },
        { text: 'Is Admin', sortable: false, value: 'isAdmin'},
      ],
   userdata: [], // Here you datatable will be able to access it.
    }),

    methods: {
        aUserData() {
            firebase.db
            .collection('cUsers').get().then((querySnapShot) => {
                // this.userdata = [] // This does not get exposed to template
                querySnapShot.forEach((doc) => {
                    this.userdata.push({
                        name: doc.data().name,
                        email: doc.data().email,
                        isAdmin: doc.data().isAdmin               
                    })
                })
            })      
        },

        getitemcontrols() {
            return `item.isAdmin`;
        },
    },

    mounted() {
        
    },

    created(){
        this.aUserData(); 
    },

    computed: {
        user() {
            return this.$store.getters.user
        },
    }
}
</script>

Also, if I may suggest, stick to consistent camelCase variable/methods names, makes reading code much easier, and once you get used to using camelCase, makes it easier to spot mistakes.另外,如果我可以建议的话,坚持使用一致的camelCase命名法变量/方法名称,使阅读代码更容易,并且一旦您习惯使用驼峰命名法,就更容易发现错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM