uniapp vue 前端页面半小时选择器

javascript 复制代码
<template>
  <view>
    <view class="uni-title uni-common-pl">时间选择器</view>
    <view class="uni-list">
      <view class="uni-list-cell">
        <view class="uni-list-cell-left">
          当前选择
        </view>
        <view class="uni-list-cell-db">
          <picker mode="selector" :value="timeIndex" range="{{timeRange}}" @change="bindTimeChange">
            <view class="uni-input">{{time}}</view>
          </picker>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      time: '', // 当前选择的时间
      timeIndex: 0, // 当前选择的时间索引
      timeRange: [] // 时间选择器的可选项
    };
  },
  mounted() {
    this.generateTimeRange();
  },
  methods: {
    generateTimeRange() {
      const startTime = new Date("2000/01/01 08:00");
      const endTime = new Date("2000/01/01 22:00");

      const timeOptions = [];
      while (startTime <= endTime) {
        const hour = String(startTime.getHours()).padStart(2, '0');
        const minute = String(startTime.getMinutes()).padStart(2, '0');
        const timeOption = `${hour}:${minute}`;
        timeOptions.push(timeOption);

        startTime.setMinutes(startTime.getMinutes() + 30);
      }

      this.timeRange = timeOptions;
      this.time = timeOptions[0];
    },
    bindTimeChange(e) {
      const selectedTimeIndex = e.mp.detail.value;
      this.timeIndex = selectedTimeIndex;
      this.time = this.timeRange[selectedTimeIndex];
    }
  }
};
</script>
相关推荐
程序员小易20 小时前
前端轮子(1)--前端部署后-判断页面是否为最新
前端·vue.js·node.js
xiaoxue..20 小时前
列表转树结构:从扁平列表到层级森林
前端·javascript·算法·面试
小oo呆20 小时前
【自然语言处理与大模型】LangChainV1.0入门指南:核心组件Agent
前端·javascript·easyui
Hao_Harrision21 小时前
50天50个小项目 (React19 + Tailwindcss V4) ✨ | DrawingApp(画板组件)
前端·react.js·typescript·tailwindcss·vite7
dly_blog21 小时前
Vite 原理与 Vue 项目实践
前端·javascript·vue.js
计算机毕设VX:Fegn089521 小时前
计算机毕业设计|基于springboot + vue汽车销售系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·汽车·课程设计
仅此,21 小时前
前端接收了id字段,发送给后端就变了
java·前端·javascript·spring·typescript
Lovely Ruby21 小时前
[前端] 封装一下 echart 6,发布到 npm
前端·npm·node.js
BD_Marathon21 小时前
NPM_常见命令
前端·npm·node.js
绿鸳21 小时前
12.17面试题
前端