Vue.js + Firebase无限循环方法

时间:2018-07-10 07:01:09

标签: firebase vue.js google-cloud-firestore

我遇到一个问题,试图在表格中显示从Firestore提取的数据。我认为这与数据更改和导致重新呈现有关,但我不确定如何解决。本质上,我试图筛选状态为“活动”的用户,然后打印其名称和电子邮件。我使用计算所得的组件来获取一个数组,其中包含用户的姓名和电子邮件作为属性。是什么导致无限循环?谢谢!

HTML

<table>
    <thead>
      <tr>
        <th>Name</th>
        <th>Email</th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="user in users">
        <td>{{ user.name }}</td>
        <td>{{ user.email }}</td>
      </tr>
    </tbody>
  </table>

JavaScript

  computed: {
    users() {
     var self = this
     let list = []
     firebase.firestore().collection('users').where('status_active','==', 
     true).get()
     .then (snapshot => {
       snapshot.forEach(doc => {
         list.push({
            name: doc.data().name,
            email: doc.data().email
          })
       })
     }).then(() => {
     return list
     })
   }
 }

0 个答案:

没有答案
相关问题