【发布时间】:2019-01-17 06:32:13
【问题描述】:
我正在使用 VueFire 和 Firebase 构建网络应用程序。
我的实时数据库中有两个集合:
cities:{
0: {
name: Berlin,
countryId: 0
},
1: {
name: Paris,
countryId: 1
},
...
},
countries:{
0: {
name: Germany,
},
1: {
name: France,
},
...
},
在 Vue 组件中,我试图获取(城市名称 + 国家名称)的列表:
<div v-for="(city, indx) in cities" :key="indx">
<div>{{city.name}}, {{countries[city.countryId].name}}</div>
</div>
export default {
firebase: {
cities: db.ref('cities'),
countries: db.ref('countries'),
}
}
出现此错误:
[Vue warn]: Error in render: "TypeError: Cannot read property
'countryId' of undefined"
如果只有 {{city.name}} - 好的。
怎么了?如何以正确的方式绑定这 2 个集合以获得我想要的?
【问题讨论】:
-
而这个 {{cities[0].countryId}} 也会导致同样的错误
标签: firebase firebase-realtime-database vue.js vuefire