Coder Social home page Coder Social logo

pzr110 / wxapp-datepicker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ifency/wxapp-datepicker

0.0 0.0 0.0 12.38 MB

微信小程序 日期时间选择器含有今天,明天,后天的,格式如MM月MM日 周几 HH:MM,支持只要今天,明天,后天,支持转换为日期格式。原生,wepy,taro,wepy都适用

JavaScript 100.00%

wxapp-datepicker's Introduction

小程序 - 日期时间选择器

含有今天,明天,后天的关键词,wepy,Taro,wepy或者原生都可引用

日期时间选择器demo

使用的方法:

  • 先引用js文件:

  • wxml文件插入picker多列选择器

<view class="section">
  <picker mode="multiSelector" range="{{dateArray}}" value="{{dateIndex}}" bindchange="datePickerChange">
  <view class="section-val">{{dateVal}}</view>
  </picker>
</view>
  • 然后在js文件上引入日期选择的文件里实例化对象,如下
//引入datePicker的实例对象
import { DatePicker } from '../utils/datePicker2';

//实例化对象
const datePicker = new DatePicker();
//制造日期的数组数据
const dateArr = datePicker.datePicker();
  • 然后把dateArr传给range的值(dateArray);
this.setDate({
    dateArray: dateArr.dateAll,
})
  • value这个值,如果不传的话,默认值就是当前时间
this.setDate({
    dateArray: dateArr.currentDateArr,
})
  • 仅仅展示“今天 某某时间“,这倒可以的,但需要把这个时间传给接口时,这就需要转换为日期格式的,所以我这边还提供能转换日期格式的功能,使用如下:
//需要把range,当前选择的下标一起携带去
this.setData({
    dataVal: datePicker.toDate(dateArr.dateAll,dateArr.currentDateArr)
})

这样就可以了。

但如果只需要第一列只需要“今天,明天,后天”这三个的话,那实例化对象给个这三个的就可以了,如下:

const params={
    dateArr:['今天','明天','后天']
}
const datePicker = new DatePicker(params);

效果如下: 日期时间选择器demo

不错的话,请点start,笔芯~当然如果还有问题的话,可以提出来

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.