微信小程序自己封装了三种选择器,通过mode来区分,分别是普通选择器、时间选择器、日期选择器,默认是普通选择器。

效果如下:

具体的看看代码,布局:

<view class="container">
  <view class="section" >  
  <picker bindchange="bindPickerChange" value="{{index}}" range="{{objectArray}}" mode = "selector">  
    <view class="picker">  
      国家:{{objectArray[index]}}  
    </view>  
  </picker>  
</view>  

<view class="section">  
  <picker mode="time" value="{{time}}" start="00:00" end="23:59" bindchange="bindTimeChange">  
    <view class="picker">  
     时间 : {{times}}
    </view>  
  </picker>  
</view>  
<view class="section">  
  <picker mode="date" value="{{date}}" start="1978-01-01" end="2017-1-23" bindchange="bindDateChange">  
    <view class="picker">  
      日期: {{dates}}  
    </view>  
  </picker>  
</view>
</view>

 css样式:

.section{
  background:#79fff4;
  margin:20rpx;
  padding:20rpx;
  font-weight: 700;
}

js代码:

Page({
  data: {
    dates: '2024-08-26',
    times: '12:00',
    objectArray: ['中国', '英国', '美国'],
    index: 0,
  },
  //  点击时间组件确定事件  
  bindTimeChange: function (e) {
    console.log("bindTimeChange")
    this.setData({
      times: e.detail.value
    })
  },
  //  点击日期组件确定事件  
  bindDateChange: function (e) {
     console.log('bindDateChange')
    this.setData({
      dates: e.detail.value
    })
  },
  //  点击城市组件确定事件  
  bindPickerChange: function (e) {
     console.log('bindPickerChange')
    this.setData({
      index: e.detail.value
    })
  },

结尾:样例小程序二维码,我自己做的一个免费好用的【随机选择决定转盘工具】小程序,欢迎扫码体验呦!

谢谢阅读!~~

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐