【发布时间】:2021-10-06 20:53:25
【问题描述】:
任务是:为一周中的每一天使用特定的 CSS 样式。
我们有什么 从下面传入的 json 对象生成的几个 DIV
<template>
<div class="row">
<div v-for="(e, i) in inventory"
:key="e.PreorderID + e.ArticleNumber" >
<div class="col s2 m3" v-if="e.Hidden == false" >
<!-- The following DIV should be getting a specific CSS class based on the day of the week -->
<div class="card blue-grey darken-1" >
Vurrent date {{ formatDate(e.DeliveryDate) }}h
</div>
</div>
</div>
</div>
</template>
我们的代码部分有一个很好的 formatDate 函数,它提供了结构化的数据格式
<script>
const dateOptions = {
weekday: "long",
hour: 'numeric',
year: "numeric",
month: "numeric",
day: "numeric",
minute: 'numeric' ,
hourCycle : "h24"
};
export default {
data() {
return {
inventory: []
};
},
mounted() {
this.load();
setInterval(this.load, 10000);
},
methods: {
load() {
fetch("http://localhost:8081/api/v1/prod/inventory")
.then((res) => res.json())
.then((data) => (this.inventory = data))
.catch((err) => console.log(err.message));
},
formatDate(inStr) {
const d = new Date(inStr);
return d.toLocaleDateString("de-DE", dateOptions);
},
},
};
</script>
我是 vue 的初学者?你们将如何解决这个问题。 问候 迈克尔
【问题讨论】:
标签: javascript vue.js vuejs3