点击下拉出几个选项,根据日期不同来过滤数据。看图--(忽略小梨子,这是日常练手页面)

(element ui)

点击today-当天日期

点击last three days

点击custom,并且实现右侧结束日期必须大于左侧(左边先选,右边无法选择比左边小的)

首先呢--先弄它个按钮下拉玩玩,,下拉数据v-for遍历,

@click.native="filterTime(menu)" 
根据interval不同来判断不同时间段(在data--menus中)
<el-dropdown size="small" trigger="click">
<el-button type="primary">
paid Time<i class="el-icon-arrow-down el-icon--right" />
</el-button>
<el-dropdown-menu>
<el-dropdown-item v-for="menu in menus" @click.native="filterTime(menu)">
{{ menu.title }}
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>

获取到的日期渲染到页面上--

   <span v-if="timeData">
<el-tag
color="white"
style="font-size: 15px;"
>
{{ timeData }}
</el-tag>
</span>

日期选择是点击弹出个弹窗,在弹窗中选择。,

:picker-options="pickerOptionsStart"   
:picker-options="pickerOptionsEnd"  
在data中判定起止时间大于的问题
<el-dialog title="Choice Time" :visible.sync="dialogVisible" width="40%">
<div style="padding-top: 10px;" :data="timePo">
<el-date-picker
v-model="start"
type="date"
value-format="yyyy-MM-dd"
placeholder="Choose the date and time"
:picker-options="pickerOptionsStart"
style="margin-right: 10px;"
@change="startTimeStatus"
/>
to
<el-date-picker
v-model="end"
type="date"
value-format="yyyy-MM-dd"
placeholder="Choose the date and time"
:picker-options="pickerOptionsEnd"
style="margin-left: 10px;"
@change="endTimeStatus"
/>
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="cancel">cancel</el-button>
<el-button type="primary" @click="saveTime">submit</el-button>
</div>
</el-dialog>

下面是一些数据,start是开始日期,end是结束日期。menus为下拉框中数据。

data() {
return {
start: '',
end: '',
dialogVisible: false,
timeData: '',
menus: [
{ title: 'today', interval: 0 },
{ title: 'yesterday', interval: 1 },
{ title: 'Last Three Days', interval: 2 },
{ title: 'one Week', interval: 6 },
{ title: 'custom', interval: -1 }
],
pickerOptionsStart: {
disabledDate: time => {
const endDateVal = this.end
if (endDateVal) {
return time.getTime() > new Date(endDateVal).getTime()
}
}
},
pickerOptionsEnd: {
disabledDate: time => {
const beginDateVal = this.start
if (beginDateVal) {
return time.getTime() < new Date(beginDateVal).getTime()
}
}
}
}
},

在methods中 ,,年+月+日,简单的获取和赋值,调用:时间戳转换成  xxxx-xx-xx格式。

            timeFormat(date) {
const year = date.getFullYear()
let month = (date.getMonth() + 1) + ''
month = month.length === 1 ? '0' + month : month
let day = date.getDate() + ''
day = day.length === 1 ? '0' + day : day
return year + '-' + month + '-' + day
},

根据前面说的来判定。timePo是后台提供的字段,获取到的start,end日期通过props传值,后台来进行过滤。

if对比不等于 -1 ,不等于的话  获取当天时间定义为end,减去选择的天数是start。endStr和startStr是转换格式后的日期。

filterTime(menu) {
const interval = menu.interval
if (interval !== -1) {
const end = new Date()
const time = end.getTime() - interval * 24 * 60 * 60 * 1000
const start = new Date(time)
const endStr = this.timeFormat(end)
const startStr = this.timeFormat(start)
this.timePo = Object.assign(this.timePo,
{
field: 'updated_at',
start: startStr + this.split + '00:00:00',
end: endStr + this.split + '23:59:59'
这里为啥这样呢,是因为在过滤的时候没加这些,有部分订单是不显示的(俺也不知道具体为啥)
}
)
this.timeData = startStr + ' => ' + endStr
this.fatherInit()
} else {
this.start = ''
this.end = ''
this.dialogVisible = true
}
},

下面是弹窗中日期的赋值,。

 // 弹窗赋值
saveTime() {
this.timeData = this.start + ' => ' + this.end
this.dialogVisible = false
this.timePo = Object.assign(this.timePo,
{
field: 'updated_at',
start: this.start + this.split + '00:00:00',
end: this.end + this.split + '23:59:59'
}
)
this.fatherInit()
},
cancel() {
this.dialogVisible = false
},
// 时间开始选择器
startTimeStatus: function(value) {
this.start = value
},
// 时间结束选择器
endTimeStatus: function(value) {
this.end = value
}
}

over。

vue框架中实现今天昨天前天最近时间的更多相关文章

  1. 如何在vue框架中兼容IE

    IE目前已经放弃了自己的独特化,正一步步迎入互联网的主流怀抱.但迫于有用户存在,还是要兼容到IE8,9, 以上. 下面聊一下如何在vue框架中兼容IE 1.首先在index.html <meta ...

  2. vue框架中props的typescript用法

    vue框架中props的typescript用法 在vue中使用typescript时,需要引入vue-property-decorator库来兼容格式. javascript写法 Vue.compo ...

  3. vue框架中的日期组件转换为yyy-mm-dd格式

    最近在用vue框架写一个app,这个是用到的日期格式转换,把下面的标准格式转换为字符串连接格式

  4. yarn 在Vue框架中的常用命令

    初始化项目 yarn add init 安装vue yarn add vue 安装webpack,webpack-dev-server(是一个小型的Node.js Express服务器) yarn a ...

  5. 在Vue框架中使用百度地图

    1.首先在index.html中引入百度地图 <script type="text/javascript" src="http://api.map.baidu.co ...

  6. Vue 框架中遇到的诀窍

    问题一. 我需要渲染数组A,并根据 B数组中是否存在A中,给A添加 选中状态sel. 经过很焦虑的研究后,寻求帮助得到答案. 1.初始化数据时 A添加属性flag(bool)标识,如果B中存在A中某个 ...

  7. vue框架中什么是MVVM

    前端页面中使用MVVM的思想,即MVVM是整个视图层view的概念,属于视图层的概念. MVVM是前端视图层的分层开发思想,将页面分成了Model, View,和VM:其中VM是核心,因为VM是V和M ...

  8. vue框架中的Axios封装

      function axios(options) {     let promise = new Promise((resolve, reject) => {         var xhr ...

  9. js获得昨天前天明天时间以及setDate()

    <script type="text/javascript"> function GetDateStr(AddDayCount) { var dd = new Date ...

随机推荐

  1. IDEA unable to find valid certification path to requested target

    一.报错 Could not transfer artifact org.apache.maven.plugins:maven-install-plugin:pom:2.4 from/to alima ...

  2. 你肯定不知道的oracle数据库和sql server的这些区别

    它们两者之间的区别主要体现在六大方面: 一是开放性. 1.SQL Server 只可在windows上运行,缺乏开放性,操作系统的稳定对数据库是非常重要的. Windows9X系列产品比较偏重于桌面应 ...

  3. (21)UML类图学习及使用

    UML类图的学习和使用 1.参考博客http://www.uml.org.cn/oobject/201211231.asp

  4. TC39 - 新特性

    tc39/proposal-hashbang: #! for JS 某些奇怪的报错可能是因为系统不支持 Shebangs / Hashbang 导致的. 貌似 Node.js 已经支持这个新特性了,使 ...

  5. MySQL-default设置

    Both statements insert a value into the phone column, but the first inserts a NULL value and the sec ...

  6. VMware 虚拟化编程(3) —VMware vSphere Web Service API 解析

    目录 目录 前文列表 VMware vSphere Web Services API VMware vSphere Web Services SDK vSphere WS API 中的托管对象 Man ...

  7. 阶段1 语言基础+高级_1-3-Java语言高级_02-继承与多态_第2节 抽象类_14-抽象的概念

    先来了解什么叫做抽象 父类有个计算面积的方法,但是不同的图形计算面积的方式是不一样的.所以这里的计算面积的方法就是个抽象的方法. 只有到具体的子类里面才能去实现具体的计算面积的方法 动物类是父类.有吃 ...

  8. Jmeter之Switch Controller

    在测试过程中,各种不同的情况需要执行不同的操作,这个时候用if控制器比较麻烦,此时就可以使用Switch Controller代替. 一.界面显示 二.配置说明 1.名称:标识 2.注释:备注 3.S ...

  9. 类Runtime

    Runtime类的概述和使用 Runtime类概述 每个Java应用程序都有一个Runtime类实例,使应用程序能够与其运行的环境相连接.可以通过getRuntime方法获取当前运行时. 应用程序不能 ...

  10. c# 解决Socket问题——由于目标机器积极拒绝,无法连接

    关于单机出现这种问题不多赘述,主要阐述服务机和客户机出现这种问题的解决办法. 1.检查防火墙 这种问题出现的最多,特别是你的服务机还是买的各家的云产品,比如阿里云就是到防火墙中添加出入站规则,Azur ...