el-date-picker筛选时间日期选择范围

el-date-picker

javascript 复制代码
选择时间日期范围-> 昨天  近7天  30天
javascript 复制代码
<template>
  <div class="main">
    <div class="header">
      <el-form :model="form" label-width="auto">
        <el-button plain @click="setTimeToYesterday" style="margin: 0 10px; float: left">昨天</el-button>
        <el-button plain @click="setTimeToLast7Days" style="margin: 0 -10px; float: left">近7日</el-button>
        <el-button plain @click="setTimeToLast30Days" style="margin: 0 10px; float: left">30日</el-button>
        <el-date-picker
          style="width: 200px; float: left"
          v-model="form.time"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始时间"
          end-placeholder="结束时间"/>
          </el-form>
         </div>
  </div>
</template>

<script lang='ts'>
import { ref, reactive, toRefs, onUnmounted, onMounted } from "vue";
import { useRouter, useRoute } from "vue-router"; //引入路由
export default {
  name: "",
  setup() {
    let router = useRouter(),
    route = useRoute();
    const data: any = reactive({
      form: {
        time: ""
      },
    });
     const setTimeToYesterday=()=> {
        const end = new Date();
        const start = new Date();
        start.setDate(start.getDate() - 1);
        start.setHours(0, 0, 0, 0);
        end.setHours(23, 59, 59, 999);
        data.form.time = [start, end];
      };
      const setTimeToLast7Days=()=>  {
        const end = new Date();
        const start = new Date();
        start.setDate(start.getDate() - 7);
        start.setHours(0, 0, 0, 0);
        end.setHours(23, 59, 59, 999);
        data.form.time = [start, end];
      };
      const setTimeToLast30Days=()=> {
        const end = new Date();
        const start = new Date();
        start.setDate(start.getDate() - 30);
        start.setHours(0, 0, 0, 0);
        end.setHours(23, 59, 59, 999);
        data.form.time = [start, end];
      };
    onMounted(() => {
    });

    onUnmounted(() => {
    });

    const refData = toRefs(data);
    return {
      ...refData,
      setTimeToYesterday,
      setTimeToLast7Days,
      setTimeToLast30Days,
    };
  },
};
</script>

<style lang="scss" scoped>
::v-deep.el-form-item__label-wrap {
  margin: 0 !important;
}
.main {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  .header {
    display: flex;
    vertical-align: middle;
    padding: 15px 0 0 0;
  }
  .section {
    flex: 5;
    padding: 0 10px;
    box-sizing: border-box;
  }
}
</style>
相关推荐
夕阳_醉了2 小时前
JS里面Map的使用以及与Object的对比
前端·javascript·vue.js
95岁IT民工3 小时前
大屏项目使用css混合实现光源扫描高亮效果
前端·css·vue.js
像污秽一样4 小时前
简易记事本开发-(SSM+Vue)
java·vue.js·spring boot·spring·servlet·maven·mybatis
2401_857026234 小时前
SSM 框架结合 Vue 实现电脑测评系统:助力用户明智选择
前端·javascript·vue.js
阿斯卡码7 小时前
服务器运行Vue项目
运维·服务器·vue.js
gaoenyang7605257 小时前
用vscode,进行vue开发
ide·vue.js·vscode·前端与后台
m0_748254098 小时前
【vue】在页面右下角添加悬浮按钮组件
前端·javascript·vue.js
章若楠圈外男友8 小时前
vsCode 报错[vue/no-v-model-argument]e‘v-model‘ directives require no argument
javascript·vue.js·vscode
kuilaurence8 小时前
Mitt 库使用笔记
javascript·vue.js