Vue.js 如何在vuejs方法中从数组中获取对象

Vue.js 如何在vuejs方法中从数组中获取对象,vue.js,google-cloud-firestore,Vue.js,Google Cloud Firestore,在我的数据中: export default { data() { return { colaborador: [], colRestaurante: '', } } 在我的报告中: created() { this.consultarColaboradores() }, 在方法上: methods: { async consultarColaboradores() { ...

在我的数据中:

export default {

  data() {
    return {
      colaborador: [],
      colRestaurante: '',
    }
  }
在我的报告中:

created() {
    this.consultarColaboradores() 
  },
在方法上:

methods: {

async consultarColaboradores() {       
       ...
          if(userNameDoc.exists) {
            let userName = userNameDoc.data()

            let colaboradorDoc = await db.collection('usuarios')
                                    .doc(userName.uid)
                                    .collection('Colaboradores')
                                    .where("uidCol", '==', auth.currentUser.uid)
                                    .get()

                colaboradorDoc.docs.forEach(doc => {                    
                    let colab = doc.data()

                      this.colaborador.push(colab)

                      let colR = this.colaborador.find(colR => colR.uidCol == auth.currentUser.uid)

                        if (colR.SistemaApp == "Restaurante") {

                            this.colRestaurante.push(colR)
                        }
          }
    ...
}
因此,我可以获得de arraycolaborador,但无法获得对象colrestaurant

在我的html中:

<template>
  <div>{{ colaborador }}</div> //RESULT [{ "username": carlos, "SistemaApp": Restaurante }]
  <div>{{colRestaurante}}</div> // RESULT ... NOTHING
</template>

{{colaborador}//RESULT[{“username”:carlos,“SistemaApp”:restaurant}]
{{colrestaurant}}//结果。。。没有什么
我错过了什么?。我期望得到这个:

{“用户名”:卡洛斯,“SistemaApp”:餐厅}


有什么可以帮我的吗?

U将
colrestaurant
定义为字符串类型,并且在您的代码中您正在做这样的事情:

this.colRestaurante.push(colR)
你不能把smth推到字符串上

然后尝试调试此代码:

colR.SistemaApp == "Restaurante"
也许这个
colR.sistemapp
永远不可能等同于
“restaurant”
。并使用
==
而不是
=