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>
相关推荐
0思必得05 分钟前
[Web自动化] Selenium浏览器对象属性
前端·python·selenium·自动化·web自动化
小二·10 分钟前
Python Web 开发进阶实战:边缘智能网关 —— 在 Flask + Vue 中构建轻量级 IoT 边缘计算平台
前端·python·flask
是毛毛吧13 分钟前
GitHub热榜----前端已死?AionUi 横空出世:首个开源“生成式UI”框架,让 AI 在运行时“手搓”界面
前端·开源·github
斯普信专业组17 分钟前
ReAct Agent 解析:从理论到实践的高效推理框架
前端·react.js·前端框架
徐同保17 分钟前
开发onlyoffice插件,功能是选择文本后立即通知父页面
开发语言·前端·javascript
23124_8023 分钟前
Base64多层嵌套解码
前端·javascript·数据库
程序员张336 分钟前
Element Plus SCSS 变量覆盖用法
vue.js·前端框架·element-plus
啥都不懂的小小白37 分钟前
Vue Ajax与状态管理完全指南:从数据请求到全局状态控制
vue.js·ajax·vuex·插槽系统
多看书少吃饭38 分钟前
文件预览的正确做法:从第三方依赖到企业级自建方案(Vue + Java 实战)
java·前端·vue.js
菜鸟很沉38 分钟前
Vue3 + Element Plus 实现大文件分片上传组件(支持秒传、断点续传)
javascript·vue.js