vue-时间插件,效果见图
<template>
<div class="select-time-wrapper">
<h5 class="titie">选择自提时间</h5>
<div class="select-time-content flex">
<ul class="days">
<li
v-for="(item, i) in days"
:key="i"
class="select-day"
:class="{ current: currentDay === i }"
@click="currentDay = i"
>
{{ item }}
</li>
</ul>
<ul class="time-range">
<li
v-for="(item, i) in displayTimeRange"
:key="i"
class="select-time"
@click="handleTimeClick(i)"
>
<span class="txt">{{ item }}</span>
<i class="icon"></i>
</li>
</ul>
</div>
</div>
</template> <script>
import dayjs from 'dayjs'; const checkNum = num => (num < 10 ? `0${num}` : String(num));
const suffixZero = str => `${str}:00`;
const translateToDays = {
0: '周日',
1: '周一',
2: '周二',
3: '周三',
4: '周四',
5: '周五',
6: '周六'
};
const defaultSelectedDay = 0; export default {
name: 'SelectTime',
data() {
const date = dayjs();
const tomorrow = date.add(1, 'day');
const theDayAfterTomorrow = date.add(2, 'day');
const days = [
`今日(${translateToDays[date.day()]})`,
`明日(${translateToDays[tomorrow.day()]})`,
`${theDayAfterTomorrow.format('M-DD')}(${
translateToDays[theDayAfterTomorrow.day()]
})`
]; return {
days,
currentDay: defaultSelectedDay,
initialArr: [],
maxHour: 22,
minHour: 9,
selectedTime: ''
};
},
computed: {
displayTimeRange() {
const { currentDay, initialArr, minHour, maxHour } = this;
const currentHour = new Date().getHours();
const sliceStart =
currentHour < minHour || currentHour + 1 > maxHour
? 0
: currentHour + 1 - minHour; return currentDay === defaultSelectedDay
? initialArr.slice(sliceStart)
: [...initialArr];
}
},
created() {
this.initialArr = this.generateArr();
},
methods: {
generateArr() {
const { minHour, maxHour } = this;
var arr = [];
for (let i = minHour; i < maxHour; i++) {
arr.push(
[suffixZero(checkNum(i)), '-', suffixZero(checkNum(i + 1))].join('')
);
}
return arr;
},
handleTimeClick(i) {
this.selectedTime = this.displayTimeRange[i];
}
}
};
</script> <style lang="scss" scoped>
.select-time-wrapper {
.titie {
padding: 10px;
text-align: center;
}
.select-time-content {
display: flex; .days {
width: 120px;
background-color: #ddd;
text-align: center;
}
.time-range {
flex: 1;
height: 200px;
overflow-y: scroll;
-webkit-overflow-scrolling: smooth;
}
.select-day,
.select-time {
cursor: pointer;
}
.select-day {
&.current {
background-color: #fff;
}
}
}
}
</style>

vue-时间插件,效果见图的更多相关文章
- vue使用日期时间插件layDate
项目中需要用到日期时间插件,尝试用bootstrap.element的时间插件都各有各的报错,对于一个菜鸟来说真的是很痛苦啊.终于,最后用了layDate实现了需要的功能 最终效果: 使用步骤: 1. ...
- vue+elementUI封装的时间插件(有起始时间不能大于结束时间的验证)
vue+elementUI封装的时间插件(有起始时间不能大于结束时间的验证): html: <el-form-item label="活动时间" required> & ...
- 写一个Vue loading 插件
什么是vue插件? 从功能上说,插件是为Vue添加全局功能的一种机制,比如给Vue添加一个全局组件,全局指令等: 从代码结构上说,插件就是一个必须拥有install方法的对象,这个方法的接收的第一个参 ...
- vue各种插件汇总
https://blog.csdn.net/wh8_2011/article/details/80497620(copy) Vue是什么? Vue.js(读音 /vjuː/, 类似于 view) 是一 ...
- VUE图片懒加载-vue lazyload插件的简单上手使用(优化版本)
在用VUE做项目开发的过程中,首页用到了懒加载的方法,查找了一些方法,觉得官网写得太复杂,有一篇博客不错(https://www.cnblogs.com/xyyt/p/7650539.html),但是 ...
- vue 常用插件,保存
UI组件 element- 饿了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的组件库 mint-ui- Vue 2的移动UI元素 iview- 基于 Vuejs 的开源 UI ...
- vue自定义插件封装,实现简易的elementUi的Message和MessageBox
vue自定义插件封装示例 1.实现message插件封装(类似简易版的elementUi的message) message组件 <template> <transition ...
- bootstrap时间插件 火狐不显示 完美解决方法
原文链接:http://www.phpbiji.cn/article/index/id/141/cid/4.html bootstrap时间插件火狐 bootstrap-datetimepicker火 ...
- jquery仿ios日期时间插件
Demo下载: 手机时间控件.zip 使用之前,请在页面中加入以下js和css: jquery-1.9.1.js mobiscroll.core-2.5.2.js mobiscroll.core-2. ...
- Asp.net+jquery+ajaxpro异步仿Facebook纵向时间轴效果
Asp.net+jquery+ajaxpro异步仿Facebook纵向时间轴效果 在一个项目中,用到了时间轴展示产品的开发进度,为了更好用户体验,想到了Facebook的timeline效果, 搜了一 ...
随机推荐
- shiro环境搭建及基本操作
一.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www ...
- CentOS 安装 Mongodb详解 --- 无Linux基础
先去官方下载离线安装包:https://www.mongodb.com/ ftp连接一下服务器,把离线包上传上去 XShell连接一下: 解压文件(你输一点就可以按tab键,它会自动补全):tar - ...
- koa 路由模块化(一)
1.项目目录 2.入口文件 根目录/app.js /** * koa 路由模块化 */ const Koa = require('koa'); const router = require('koa- ...
- H264编码原理以及I帧、B和P帧详解, H264码流结构分析
H264码流结构分析 http://blog.csdn.net/chenchong_219/article/details/37990541 1.码流总体结构: h264的功能分为两层,视频编码层(V ...
- LC 965. Univalued Binary Tree
A binary tree is univalued if every node in the tree has the same value. Return true if and only if ...
- 利用Viewpager和Fragment实现UI框架的搭建实现
package com.loaderman.uiframedemo; import android.os.Bundle; import android.support.v4.app.Fragment; ...
- MySQL随机字符串函数批量插入数据
简单举个例子: drop table if exists demo1 create table demo1 ( id int primary key auto_increment, name ) ...
- JMeter 中的如何区分 Server Time 和 Network Time
在 LR 中是有一个“网页细分图”的,通过这个图,你可以比较容易的区分哪些请求的响应时间最长,如果响应时间过程,是消耗在server处理的时候,还是消耗在网络传输过程中——也就是所谓的 Server ...
- Python:Base3(函数,切片,迭代,列表生成式)
1.Python之调用函数: Python内置了很多有用的函数,我们可以直接调用. 要调用一个函数,需要知道函数的名称和参数,比如求绝对值的函数 abs,它接收一个参数. 可以直接从Python的官方 ...
- Python学习之格式化简述
2.2 格式化输出 2.2.1 占位符 %s就是代表字符串占位符:%d是数字占位符,%i 也可以表示数字,如果把变量后⾯的换成%d,就代表必须只能输⼊数字这时对应的数据必须是int类型. 否则程序 ...