当前位置: 首页 > news >正文

珠海建网站公司设计学习网站

珠海建网站公司,设计学习网站,常德seo排名,企业网站seo实本文使用vue2.0elementui 制作一个上门取件时间组件#xff0c;类似顺丰#xff0c;样式如下#xff1a; 大概功能#xff1a;点击期望上门时间#xff0c;下面出现一个弹框可以选择时间#xff1a; 首先我们定义一些需要的数据#xff1a; data() {return {isDropdown…本文使用vue2.0elementui 制作一个上门取件时间组件类似顺丰样式如下 大概功能点击期望上门时间下面出现一个弹框可以选择时间 首先我们定义一些需要的数据 data() {return {isDropdown: false,dayList: [],listArray: [08:00~09:00,09:00~10:00,10:00~11:00,11:00~12:00,12:00~13:00,13:00~14:00,14:00~15:00,15:00~16:00,16:00~17:00,17:00~18:00,18:00~19:00,19:00~19:30,],timeToList: {},timeValue: 今天,clickValue: 一小时内,clickDay: 今天,time: ,}}, 接着我们画一个期望上门时间的长框点击可以出现弹窗点击外部弹窗消失这中间我们使用了import Clickoutside from element-ui/src/utils/clickoutside 这一组件来帮助我们达到这个目的 templatediv classtime-picker clickopenDown v-clickoutsideclickoutsidediv classcontent-firstdiv classredSpan*/divdiv期望上门时间/div/divdiv classcontent-firstdiv{{ time }}/divi classel-icon-s-order/i/div /template 接下来画一个弹出页面弹出页面顶部是一个tab组件这里通过daylist循环获得 div classtimediv v-foritem in dayList classitem :classtimeValue item.lable ? active : clickdayChange(item)div{{ item.lable }}/divdiv{{ item.ymd }}/div/div/div tab组件中的内容是下单时间的按钮集合通过timeToList 这个结构体 先获取数组再循环生成 div classtimeListdiv v-foritem in timeToList[timeValue] clicktimeChange(item) classtimeBox:classclickDay item.day clickValue item.lable ? active : {{ item.lable }}/div/div 页面写好了我们开始写逻辑代码先需要一些工具函数获取小时、分钟、年月日一个用来判定点击了哪个按钮的list由于是双层结构tabbutton集所以需要两个值来判定一个获取今天按钮列表的函数 getHours() {const now new Date();return now.getHours();},getMinute() {const now new Date();return now.getMinutes();},formatDate(date) {const year date.getFullYear();const month String(date.getMonth() 1).padStart(2, 0);const day String(date.getDate()).padStart(2, 0);return ${year}-${month}-${day};},transTime(arr, day) {let temp []arr.forEach((item) {temp.push({lable: item,day: day})})return temp},getTodayList(arr) {let minute this.getMinute()let hour this.getHours()if (hour 8)return arrif (hour 19 minute 30)return []arr arr.slice(hour - 7)arr [一小时内, ...arr]return arr} 然后我们需要先初始化数据 initial() {let minute this.getMinute()let hour this.getHours()if (hour 9) {this.clickValue 08:00~09:00this.clickDay 今天return}if (hour 19 minute 30) {this.clickValue 08:00~09:00this.clickDay 明天return}},然后将时间赋值这里其实可以用computed但是我还是习惯自己做这部分操作 setTime() {this.time this.clickDay this.clickValue}, 接下来我们需要生成tab表单dayList以及每个tab页面下面的时间选项用了上面的两个工具函数getTodayList(),transTime() getDay() {const today new Date()const tomorrow new Date(today)tomorrow.setDate(tomorrow.getDate() 1)const afterTomorrow new Date(today)afterTomorrow.setDate(afterTomorrow.getDate() 2)let dayArray [this.formatDate(today), this.formatDate(tomorrow), this.formatDate(afterTomorrow)]let dayName [今天, 明天, 后天]this.dayList dayName.map((item, index) {return {lable: item,ymd: dayArray[index]}})},getTimeToList() {this.dayList.forEach((item) {let arr JSON.parse(JSON.stringify(this.listArray))if (item.lable 今天)arr this.getTodayList(arr)this.timeToList[item.lable] this.transTime(arr, item.lable)})},通过上面的初始化函数,可以生成下拉页面的组件内容函数顺序如下 mounted() {this.initial()this.setTime()this.getDay()this.getTimeToList()}, 最后我们添加一些点击动作,完整代码 openDown() {//打开下来框this.isDropdown true},clickoutside(e) {//关闭下拉框if (!e) {this.isDropdown falsethis.timeValue this.clickDay}},dayChange(item) {//切换tab页面this.timeValue item.lable},timeChange(item) {//选择下单时间this.clickValue item.lablethis.clickDay item.daythis.setTime()}, 贴一下css代码 style langscss scoped .time-picker {background-color: #f4f5f7;width: 336px;height: 32px;padding: 0 6px;display: flex;justify-content: space-between;cursor: pointer;.content-first {display: flex;align-items: center;gap: 3px;.redSpan {color: red;}}.dropdown {position: absolute;top: 32px;right: 0px;z-index: 99;width: 100%;height: 220px;background-color: #fff;box-shadow: 0 8px 12px 0 rgba(0, 0, 0, 0.04);border-radius: 10px;padding: 6px;.time {display: flex;.item {width: 33%;height: 45px;text-align: center;font-size: 14px;line-height: 18px;border-bottom: 1px solid #cccccc;}.active {color: red;border-bottom: 1px solid red;}}.timeList {padding: 10px;display: flex;align-items: center;flex-wrap: wrap;gap: 10px;.timeBox {width: 93px;height: 29px;background-color: #f7f8fa;text-align: center;}.timeBox:hover {color: red;}.active {color: red;background-color: #ffefef;}}}} /style 完整代码已经上传githubhttps://github.com/majinihao123/vue-Component 有需要的自取麻烦给git一个星星 以后要开始好好搞github自己的个人项目了
http://www.dnsts.com.cn/news/22225.html

相关文章:

  • 中外商贸网站建设店面门头设计网站
  • 网站备案网站简介中山外贸网站建设公司
  • 网站 上传文件上海注销营业执照流程
  • 网站怎么更新网站建设跟加入会员哪个效果好
  • 卑鄙的网站开发公司做优惠卷网站倒闭了多少
  • 门户网站个人可以做wordpress 网盘插件
  • django网站开发实例源码汉沽天津网站建设
  • 红河做网站网站建设公司客户来源渠道
  • 网站 中文版与英文版的后台有什么不同中国核工业第五建设有限公司地址
  • 网站源码上传图片出错wordpress联系人表单
  • 网站标题和关键词一样wordpress原始密码错误
  • 定制高端网站建设青岛专业做商业房的网站
  • 海珠建网站多少钱公司网站开发有哪些
  • 做网站需要什么学历早晨网站建设
  • 精品课程网站建设 公司有了域名搭建网站详细步骤
  • 河北省建设环境备案网站邢台论坛贴吧
  • 做网站版权怎么写萧山网站优化
  • 重庆做网站泉州公司编程是什么课程内容
  • 响应式网站 移动端网站网上给别人做网站
  • 会计公司网站模板下载建设电子书阅读网站
  • 网站页面怎么算中国新冠疫苗接种率
  • app和手机网站阿里巴巴网站建设分析
  • 上海网站jianshe正能量不良网站直接进入
  • 上饶做网站哪家好免费做app
  • 网站开发后端做什么我先做个网站怎么做的
  • 企业网站模板下载需谨慎宜昌网站建设开发
  • 盘锦市网站建设邢台学校网站建设费用
  • 荆州市城市建设档案馆网站网站漏洞
  • 如何自己开发网站新乡做企业网站的公司
  • 临沂网站开发公司发外链软件