【问题标题】:Items empty after doing db bind执行数据库绑定后项目为空
【发布时间】:2019-12-14 00:48:17
【问题描述】:

所以我尝试使用 vuefire 和 vue 在列表中显示基本数据,但项目对象为空 这是列表 items.vue 文件

<template>
  <div>
    <h1>List Item</h1>
    <table class="table table-striped">
      <thead>
        <tr>
          <th>Item Name</th>
          <th>Item Price</th>
          <th colspan="2">Action</th>
        </tr>
      </thead>
      <tbody>
          <tr v-for="item of items" :key="item['.key']">
            <td>{{ item.name }}</td>
            <td>{{ item.surname }}</td>
      </tbody>
    </table>
  </div>
</template>

<script>

import { db } from '../config/db';

export default {
  components: {
      name: 'ListItem'
  },
  data() {
    return {
      items: []
    }
  },
  firebase: {
    items: db.ref('drivers')
  },
  }
}
</script>
import Firebase from 'firebase'

const firebaseConfig = {
        apiKey: "",
        authDomain: "",
        databaseURL: "",
        projectId: "",
        storageBucket: "",
        messagingSenderId: "",
        appId: ""
};
so this is my db.js file 
let app = Firebase.initializeApp(firebaseConfig)
export const db = app.database()

列表项似乎是空的,并且没有显示数据,我相信它可能与 db.ref(drivers) 有关,但我正在使用插入函数并且有效,数据库已经有 5 个条目

【问题讨论】:

    标签: javascript firebase vue.js firebase-realtime-database vuefire


    【解决方案1】:

    你添加插件了吗? (firestorePlugin 在 Firestore 的情况下)

    import { rtdbPlugin } from 'vuefire';
    
    Vue.use(rtdbPlugin);
    

    另外,drivers 是一个集合吗?那么应该是db.collection('drivers')

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-28
      • 1970-01-01
      • 1970-01-01
      • 2016-08-11
      相关资源
      最近更新 更多