具有vuefire+;firebase绑定集合错误
我正在使用VueFire和Firebase构建web应用程序 我的实时数据库中有两个集合:具有vuefire+;firebase绑定集合错误,firebase,firebase-realtime-database,vue.js,vuefire,Firebase,Firebase Realtime Database,Vue.js,Vuefire,我正在使用VueFire和Firebase构建web应用程序 我的实时数据库中有两个集合: cities:{ 0: { name: Berlin, countryId: 0 }, 1: { name: Paris, countryId: 1 }, ... }, countries:{ 0: { name: Germany, }, 1: {
cities:{
0: {
name: Berlin,
countryId: 0
},
1: {
name: Paris,
countryId: 1
},
...
},
countries:{
0: {
name: Germany,
},
1: {
name: France,
},
...
},
在Vue组件中,我尝试获取以下列表(城市名称+国家名称):
只要{{city.name}}-好
怎么了?如何以正确的方式绑定这2个集合以获得所需的内容?由于firebase需要一些时间来获取数据,因此DOM将首先加载 你可以试着这样做
firebase: {
citiesFromdb: db.ref('cities'),
countriesFromdb: db.ref('countries'),
}
computed: {
cities() {
return this.citiesFromdb;
},
countries(){
return this.countriesFromdb;
}
}
这个{cities[0].countryId}}也会导致相同的错误我已经尝试过了,使用computed(以及不同的钩子),但是不幸的是,它没有帮助解决问题。可以使用console.log(countries),或者它给出errorconsole.log(this.countries)-(5)[{…},{…},{…},{…},{…},{…},{…},ob ob ob Observer]-没有错误,数组和对象中包含所有真实数据这意味着您的国家/地区集合是一个数组,而不是您在问题中显示的数据(对象)?h,我在数据库描述中犯了一个错误。国家是一个阵列。
[Vue warn]: Error in render: "TypeError: Cannot read property
'countryId' of undefined"
firebase: {
citiesFromdb: db.ref('cities'),
countriesFromdb: db.ref('countries'),
}
computed: {
cities() {
return this.citiesFromdb;
},
countries(){
return this.countriesFromdb;
}
}