【发布时间】:2019-05-01 00:26:42
【问题描述】:
所以我有一个包含对象数组的对象。我需要抓取数组每个对象中的数据来显示营业时间。
我已成功检索到 sn-p 内 for 循环中的每个键值。但我不确定如何在我的 .vue 视图页面中显示它。
我是否使用字符串插值?我应该在 .vue 页面中使用 v-for 指令来显示数据吗?
对于 Vue JS 来说还是相当新的,所以任何帮助都将不胜感激!
import {
Vue,
Component
} from 'vue-property-decorator';
import {
namespace
} from 'vuex-class';
import FoodMerchant from '../../models/FoodMerchant';
export default class MerchantProfilePage extends Vue {
@namespace('merchant').State('foodMerchant') foodMerchant!: FoodMerchant;
openingHours() {
for (let i = 0; i < this.foodMerchant.opening_hours.data.length; i++) {
console.log(this.foodMerchant.opening_hours.data[i].startHour);
}
}
}
<button @click="openingHours()">show opening hours</button>
<div class="openingHours d-flex flex-wrap mb-10">
<div class="d-flex justify-content-between mb-10 w-100">
<h5 class="font-italic text-black font-12">
Wednesday
</h5>
<h5 class="font-italic text-black font-12 font-weight-light">
5:00pm - 11:00pm
</h5>
</div>
</div>
<div class="openingHours d-flex flex-wrap mb-10">
<div class="d-flex justify-content-between mb-10 w-100">
<h5 class="font-italic text-black font-12">
Thursday
</h5>
<h5 class="font-italic text-black font-12 font-weight-light">
5:00pm - 11:00pm
</h5>
</div>
</div>
<div class="openingHours d-flex flex-wrap mb-10">
<div class="d-flex justify-content-between mb-10 w-100">
<h5 class="font-italic text-black font-12">
Friday
</h5>
<h5 class="font-italic text-black font-12 font-weight-light">
5:00pm - 11:00pm
</h5>
</div>
</div>
<div class="openingHours d-flex flex-wrap mb-10">
<div class="d-flex justify-content-between mb-10 w-100">
<h5 class="font-italic text-black font-12">
Saturday
</h5>
<h5 class="font-italic text-black font-12 font-weight-light">
5:00pm - 11:00pm
</h5>
</div>
</div>
<div class="openingHours d-flex flex-wrap mb-10">
<div class="d-flex justify-content-between mb-10 w-100">
<h5 class="font-italic text-black font-12">
Sunday
</h5>
<h5 class="font-italic text-black font-12 font-weight-light">
5:00pm - 11:00pm
</h5>
</div>
</div>
【问题讨论】:
标签: arrays object for-loop vue.js v-for