如何正确地将(姓名、主题、日期)推送到 studentIndex:[] 谢谢!)
new Vue({
el: "#data-tag",
data: {
dataend: '',
days: '',
studentIndex: [
{nameStudentIndex:"", topicStudentIndex: "", days: ""},
]
},
watch: {
dataend(){
this.deadline();
}
},
methods: {
deadline() {
const msPerDay = 8.64 * Math.pow(10, 7);
const abs = Date.parse(this.dataend) - Date.now();
this.days = Math.ceil(abs/msPerDay);
},
addtoList() {
studentIndex.push(this.nameStudentIndex, this.topicStudentIndex, this.days);
console.log(studentIndex);
}
},
computed: {
сolorTag() {
switch(true) {
case this.days > 60: {
return 'blue'
}
case this.days < 60 && this.days>14: {
return 'yellow'
}
case this.days < 14: {
return 'red'
}
}
}
}
})
tab {
width: 140px;
height: 80px;
}
.red {background-color: red;}
.yellow {background-color: yellow;}
.blue {background-color: blue;}
#rezult {
background-color: #eee;
}
<div id="data-tag">
<input type="text" placeholder="name" v-model="nameStudentIndex">
<input type="text" placeholder="topic" v-model="topicStudentIndex">
<input type="date" placeholder="дата окончания" v-model="dataend">
<button @click="addtoList">Add</button>
<div id="rezult" v-for="studentIndexes in studentIndex">
<div>{{studentIndexes.nameStudentIndex}}</div>
<div>{{studentIndexes.nameStudentIndex}}</div>
<div> {{studentIndexes.days}} days</div>
<div :class="`tab ${сolorTag}`"></div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
在对象中创建对象
data
:添加到相应的表单域
v-model
你的属性
days
是由日期选择事件形成的,我们在它上面挂了一个处理程序。这将在
deadline
选择日期后运行该功能。在其主体中,计算后,将结果传递给days
对象的属性newStudent
填写完所有字段后,您将拥有一个
newStudent
具有必要属性的对象你可以把它“推”到一个数组中
为了清楚起见,我举一个例子。