方法一:处理日期 函数
// 处理日期
dateTime(starDay, endDay) {
const daytime = Math.abs(Date.parse(endDay) - Date.parse(starDay)) // abs 计算绝对值
const day = Math.floor(daytime / (1000 * 3600 * 24))
return day
}
处理日期函数二
dayTime(starDay, endDay) {
const star = new Date(starDay)
const end = new Date(endDay)
const daytime = Math.abs(star.getTime() - end.getTime()) // abs 计算绝对值
const day = Math.floor(daytime / (1000 * 3600 * 24))
return day
}
分别用computed 和watch 实现
computed: {
countTotal: function() {
this.progressData.forEach((item) => {
if (item.startday && item.overday) {
item.time = this. dateTime(item.startday, item.overday)
return item.time
}
})
}
},
// watch: {
// 'progressData': {
// // 设置深度监听,当openDate值发生变化时出发handler方法
// deep: true,
// // immediate: true,
// handler: function(newVal, oldVal) {
// newVal.map(item => {
// const self = this
// if (item.startday === '' || item.overday === '') {
// item.time = ''
// } else {
// item.time = self. dateTime(item.startday, item.overday)
// }
// })
// }
// }
// },
data数据
模板