我正在通过向Google Places API发出GET请求来获取视觉信息。不幸的是,某些瞄准具opening_hours本身具有一个对象场,weekday_text而open_now某些瞄准具却没有,所以我得到了错误<p v-if='sight.opening_hours && sight.opening_hours.open_now'>Open now</p><p v-if='sight.opening_hours && !sight.opening_hours.open_now'>Closed now</p><p v-if='sight.opening_hours && sight.opening_hours.weekday_text' v-for='day in this.sight.opening_hours.weekday_text'>{{ day }}</p>我的v-if是否不涵盖存在sight.opening_hours和sight.opening_hours.weekday_text不存在的情况?我认为该错误来自v-for,因为如果我删除它,一切都会正常进行。
2 回答

慕妹3146593
TA贡献1820条经验 获得超9个赞
您需要重写代码,例如“外部条件检查和内部迭代”。您可能需要template元素。
template(v-if="sight.opening_hours && sight.opening_hours.weekday_text")
p(
v-for="(day, index) in this.sight.opening_hours.weekday_text",
:key="index"
)
| {{ day }}
添加回答
举报
0/150
提交
取消