当前位置: 首页>大数据>正文

小知识积累 -- el-date-picker 日期选择器的默认

功能:根据小时/天的切换时间范围在当前日期的一周/一个月

小知识积累 -- el-date-picker 日期选择器的默认,第1张

<el-radio-group?v-model="time"?size="small"?@change="getDate">

??????????????<el-radio-button?label="小时"?/>

??????????????<el-radio-button?label="天"?/>

????????????</el-radio-group>

????????????<el-radio-group?v-if="cityTypeShow"?v-model="buildType"?size="small"?style="margin-left:20px"?@change="getBuildType">

??????????????<el-radio-button?label="默认"?/>

??????????????<el-radio-button?label="类型"?/>

????????????</el-radio-group>

????????????<el-date-picker

??????????????v-model="dateTime"

??????????????type="datetimerange"

??????????????range-separator="~"

??????????????start-placeholder="开始日期"

??????????????end-placeholder="结束日期"

??????????????size="small"

??????????????class="dateBox"

????????????/>

?data()?{

????return?{

??????time:?'天',

??????buildType:?'默认',

??????dateTime:?[ ],数据形式

}

?getDateTime()?{

??????const?start?=?new?Date()

??????let?year1,?month1,?day1;

??????[year1,?month1,?day1]?=?[start.getFullYear(),?start.getMonth(),?start.getDate()]

??????const?date1?=?new?Date(year1,?month1,?day1,?7)

??????this.dateTime.push(date1)

??????const?end?=?new?Date()

??????let?year2,?month2,?day2

??????end.setTime(end.getTime()?-?24?*?60?*?60?*?1000?*?30);

??????[year2,?month2,?day2]?=?[end.getFullYear(),?end.getMonth(),?end.getDate()]

??????const?date2?=?new?Date(year2,?month2,?day2,?7)

??????this.dateTime.unshift(date2)

????},


https://www.xamrdz.com/bigdata/7pd1997405.html

相关文章: