uni-app picker组件中date未智能判断闰年平年二月及大小月

uni-app picker组件中date未智能判断闰年平年二月及大小月

开发环境 版本号 项目创建方式
Windows 未知 HBuilderX

产品分类:uniapp/小程序/微信
PC开发环境操作系统:Windows
HBuilderX类型:正式
HBuilderX版本号:3.1.9
第三方开发者工具版本号:未知
基础库版本号:未知
App下载地址或H5网址:https://meals.xznsyh.com/merchant/h5/#/pages/select/role

示例代码:

<view class="uni-list">
<view class="uni-list-cell">
<view class="uni-list-cell-db">
<picker mode="date" :value="date1" :start="startDate" :end="endDate" [@change](/user/change)="bindDateChange1" fields='day' :disabled='disabled1'>
<view class="uni-input">{{date1!=''?date1:'请选择结束时间'}}</view>
</picker>
</view>
</view>
</view>

操作步骤:

<view class="uni-list">
<view class="uni-list-cell">
<view class="uni-list-cell-db">
<picker mode="date" :value="date1" :start="startDate" :end="endDate" [@change](/user/change)="bindDateChange1" fields='day' :disabled='disabled1'>
<view class="uni-input">{{date1!=''?date1:'请选择结束时间'}}</view>
</picker>
</view>
</view>
</view>

预期结果:

<view class="uni-list">
<view class="uni-list-cell">
<view class="uni-list-cell-db">
<picker mode="date" :value="date1" :start="startDate" :end="endDate" [@change](/user/change)="bindDateChange1" fields='day' :disabled='disabled1'>
<view class="uni-input">{{date1!=''?date1:'请选择结束时间'}}</view>
</picker>
</view>
</view>
</view>

实际结果:

<view class="uni-list">
<view class="uni-list-cell">
<view class="uni-list-cell-db">
<picker mode="date" :value="date1" :start="startDate" :end="endDate" [@change](/user/change)="bindDateChange1" fields='day' :disabled='disabled1'>
<view class="uni-input">{{date1!=''?date1:'请选择结束时间'}}</view>
</picker>
</view>
</view>
</view>

更多关于uni-app picker组件中date未智能判断闰年平年二月及大小月的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

暂时没上传过多东西,但是选择时间的时候四月份的却出了31号

更多关于uni-app picker组件中date未智能判断闰年平年二月及大小月的实战教程也可以访问 https://www.itying.com/category-93-b0.html


uni-app的picker组件在mode="date"时,其日期处理逻辑依赖于底层平台(如微信小程序)的原生实现。根据你的描述,问题出现在日期选择器未能正确处理闰年平年的二月天数及大小月变化。

这通常是因为:

  1. picker组件的日期范围验证逻辑在平台层面存在缺陷
  2. fields='day’参数可能影响了日期边界的智能判断

建议的解决方案:

  1. 在data中手动设置start和end日期范围,避开2月29日等特殊日期
  2. 使用JavaScript Date对象在bindDateChange1事件中做二次验证
  3. 考虑使用第三方日期选择器组件替代原生picker

示例代码改进:

data() {
  return {
    startDate: '2023-01-01',
    endDate: '2023-12-31'
  }
}
回到顶部