获取近一周,近30天,近半年的时间段。
<template>
<div class="daytiem">
<p @click="latestTime('7')">近一周</p>
<p @click="latestTime('30')">近30天</p>
<p @click="latestTime('180')">近半年</p>
</div>
</template>
latestTime(value) {
this.dayval = value
var date = new Date()
date= date.valueOf()
date= date- value * 24 * 60 * 60 * 1000
date= new Date(date)
const month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
const datadays = (date.getDate() < 10) ? '0' + date.getDate() : date.getDate()
console.log(date.getFullYear() + '-' + month + '-' + datadays)
}