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

实现vant的年月日时分秒组件

方法:van-datetime-picker(type:datetime)和 van-picker结合实现。

<template><div class="datetimesec-picker"><van-datetime-pickerref="timePickerRef"type="datetime" //年月日时分v-model="currentDate":show-toolbar="false":visible-item-count="7"@confirm="onTimeConfirm"/><van-pickerclass="sec-picker":default-index="secondIdx":show-toolbar="false":visible-item-count="7":columns="Array(60).fill().map((_, i) => `0${i}`.slice(-2))" //秒@change="handleSecChange"/></div><div @click="toggleTimeConfirm"><span class="flex justify-center items-center fw-600 text-18px c-#fff">下一步</span></div>
</template><script setup>
import momentMini from 'moment-mini'const formData = reactive({startDate:momentMini(new Date()).subtract(1, 'day').format('YYYY-MM-DD HH:mm:ss'),
})
const timePickerRef = ref(null)
const currentDate = ref(new Date(new Date().getTime() - 1 * 24 * 60 * 60 * 1000),
) //默认往前1天
const secondIdx = ref(null) //默认秒数索引
const handleSecChange = (val, idx) => {secondIdx.value = idx
}watch(() => formData.startDate,nV => {secondIdx.value = Number(nV.slice(-2))},{ immediate: true },
)//点击‘下一步’
const toggleTimeConfirm= () => {//触发datetime-picker的confirm钩子timePickerRef.value.getPicker().confirm()
}
const onTimeConfirm= value => {formData.startDate= `${momentMini(new Date(value)).format('YYYY-MM-DD HH:mm:ss').slice(0, -2)}${addZero(secondIdx.value)}`
}// 一位数字前面补零
const addZero = (num) => {return num < 10 ? `0${num}` : num;
}
</script><style lang="scss" scoped>
.datetimesec-picker {display: flex;.van-picker:first-of-type {flex: 5;}.van-picker:last-of-type {flex: 1;}
}
</style>

参考文章:

van-datetimesec-picker - npm

http://www.lryc.cn/news/345636.html

相关文章:

  • typescript 命名空间、装饰器
  • GPT问答SAP BW
  • 使用zdppy_amauth开发激活用户接口
  • c++ memset 指针示例
  • 24考研双非上岸武汉理工大学电子信息专硕,855考研经验
  • 使用KubeKey 快速交付k8s v1.28.8集群
  • nginx--压缩https证书favicon.iconginx隐藏版本号 去掉nginxopenSSL
  • 通俗的理解网关的概念的用途(四):什么是网关设备?(网络层面)
  • Spring JdbcTemplate实现自定义动态sql拼接功能
  • 第十一篇:操作系统新纪元:智能融合、量子跃迁与虚拟现实的交响曲
  • 【大数据】学习笔记
  • PHP 框架安全:ThinkPHP 序列 漏洞测试.
  • 厂家自定义 Android Ant编译流程源码分析
  • 基于springboot+vue+Mysql的体质测试数据分析及可视化设计
  • uniapp的app端推送功能,不使用unipush
  • 数据结构(四)————二叉树和堆(中)
  • 随便写点东西
  • Mac 报错 Zsh: command not found :brew
  • 分析师常用商业分析模型
  • KMeans,KNN,Mean-shift算法的学习
  • web前端笔记8
  • 【漏洞复现】Apahce HTTPd 2.4.49(CVE-2021-41773)路径穿越漏洞
  • API低代码平台介绍2-最基本的数据查询功能
  • 面试经典150题——盛最多水的容器
  • Box86源码解读记录
  • Azure AKS日志查询KQL表达式
  • Set接口
  • vue2结合element-ui实现TreeSelect 树选择功能
  • Python运维之定时任务模块APScheduler
  • Linux技能