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>
相关推荐
最爱老式锅包肉1 小时前
《HarmonyOS技术精讲-ArkWeb》桥接两岸:JSBridge原生与Web互调
前端·华为·harmonyos
IT_陈寒2 小时前
闭包陷阱让我加了两天班,JavaScript你真行
前端·人工智能·后端
踩着两条虫2 小时前
可视化 vs 终端 vs 云端:VTJ.PRO、Claude Code、Codex 三强横评
前端·vue.js·人工智能·低代码·架构
kyriewen2 小时前
Godot 全面封杀 Vibe Coding,作为每天用 AI 写代码的人,我反而觉得这是件好事
前端·ai编程·claude
前进的搬砖er2 小时前
4.three.js的几何体、纹理、光源、材质、uv属性 讲义
前端
前端毕业班2 小时前
uni-app 小程序支持 teleport 了
前端·javascript·vue.js
梨子同志3 小时前
qiankun
前端
梨子同志3 小时前
Nginx
前端
梨子同志3 小时前
NestJS
前端
梨子同志3 小时前
Next.js
前端