Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue2-datepicker

Package Overview
Dependencies
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue2-datepicker

A Datepicker Component For Vue2

  • 3.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
72K
decreased by-18.92%
Maintainers
1
Weekly downloads
 
Created
Source

vue2-datepicker

中文版

A Datepicker Component For Vue2

build:passed Badge npm MIT

Demo

https://mengxiong10.github.io/vue2-datepicker/index.html

image

Install

$ npm install vue2-datepicker --save

Usage

<script>
  import DatePicker from 'vue2-datepicker';
  import 'vue2-datepicker/index.css';

  export default {
    components: { DatePicker },
    data() {
      return {
        time1: null,
        time2: null,
        time3: null,
      };
    },
  };
</script>

<template>
  <div>
    <date-picker v-model="time1" valueType="format"></date-picker>
    <date-picker v-model="time2" type="datetime"></date-picker>
    <date-picker v-model="time3" range></date-picker>
  </div>
</template>

Theme

If your project uses SCSS, you can change the default style variables.

To create a scss file. e.g. datepicker.scss:

$default-color: #555;
$primary-color: #1284e7;

@import '~vue2-datepicker/scss/index.scss';

Internationalization

The default language of v3.x is English. If you need other locales. You can import locale file. Once you import a locale, it becomes the active locale.

import DatePicker from 'vue2-datepicker';
import 'vue2-datepicker/index.css';

import 'vue2-datepicker/locale/zh-cn';

You can also override some of the default locale by lang. Full config

<script>
  export default {
    data() {
      return {
        lang: {
          formatLocale: {
            firstDayOfWeek: 1,
          },
          monthBeforeYear: false,
        },
      };
    },
  };
</script>

<template>
  <date-picker :lang="lang"></date-picker>
</template>

Props

PropDescriptionTypeDefault
typeselect the type of pickerdate |datetime|year|month|time|week'date'
rangeif true, pick the range datebooleanfalse
formatto set the date format. similar to moment.jstoken'YYYY-MM-DD'
value-typedata type of the binding valuevalue-type'date'
default-valuedefault date of the calendarDatenew Date()
langoverride the default localeobject
placeholderinput placeholder textstring''
editablewhether the input is editablebooleantrue
clearableif false, don't show the clear iconbooleantrue
confirmif true, need click the button to change valuebooleanfalse
confirm-textthe text of confirm buttonstring'OK'
disableddisable the componentbooleanfalse
disabled-datespecify the date that cannot be selected(date) => boolean-
disabled-timespecify the time that cannot be selected(date) => boolean-
append-to-bodyappend the popup to bodybooleantrue
inlinewithout inputbooleanfalse
input-classinput classnamestring'mx-input'
input-attrinput attrs(eg: { name: 'date', id: 'foo'})object
openopen state of pickerboolean-
popup-stylepopup styleobject
popup-classpopup classes
shortcutsset shortcuts to selectArray<{text, onClick}>-
title-formatformat of the tooltip in calendar celltoken'YYYY-MM-DD'
partial-updatewhether update date when select year or monthbooleanfalse
range-separatortext of range separatorstring' ~ '
show-week-numberdetermine whether show week numberbooleanfalse
hour-stepinterval between hours in time picker1 - 601
minute-stepinterval between minutes in time picker1 - 601
second-stepinterval between seconds in time picker1 - 601
hour-optionscustom hour columnArray<number>-
minute-optionscustom minute columnArray<number>-
second-optionscustom second columnArray<number>-
show-hourwhether show hour columnbooleanbase on format
show-minutewhether show minute columnbooleanbase on format
show-secondwhether show second columnbooleanbase on format
use12hwhether show ampm columnbooleanbase on format
show-time-headerwhether show header of time pickerbooleanfalse
time-title-formatformat of the time headertoken'YYYY-MM-DD'
time-picker-optionsset fixed time list to selecttime-picker-optionsnull
Token
UintTokenoutput
YearYY70 71 ... 10 11
YYYY1970 1971 ... 2010 2011
Y-1000 ...20 ... 1970 ... 9999 +10000
MonthM1 2 ... 11 12
MM01 02 ... 11 12
MMMJan Feb ... Nov Dec
MMMMJanuary February ... November December
Day of MonthD1 2 ... 30 31
DD01 02 ... 30 31
Day of Weekd0 1 ... 5 6
ddSu Mo ... Fr Sa
dddSun Mon ... Fri Sat
ddddSunday Monday ... Friday Saturday
AM/PMAAM PM
aam pm
HourH0 1 ... 22 23
HH00 01 ... 22 23
h1 2 ... 12
hh01 02 ... 12
Minutem0 1 ... 58 59
mm00 01 ... 58 59
Seconds0 1 ... 58 59
ss00 01 ... 58 59
Fractional SecondS0 1 ... 8 9
SS00 01 ... 98 99
SSS000 001 ... 998 999
Time ZoneZ-07:00 -06:00 ... +06:00 +07:00
ZZ-0700 -0600 ... +0600 +0700
Week of Yearw1 2 ... 52 53
ww01 02 ... 52 53
Unix TimestampX1360013296
Unix Millisecond Timestampx1360013296123
custom format

the format accepts an object to customize formatting.

<date-picker :format="momentFormat" />
data() {
  return {
    // Use moment.js instead of the default
    momentFormat: {
      // Date to String
      stringify: (date) => {
        return date ? moment(date).format('LL') : ''
      },
      // String to Date
      parse: (value) => {
        return value ? moment(value, 'LL').toDate() : null
      }
    }
  }
}

value-type

set the format of binding value

ValueDescription
'date'return a Date object
'timestamp'return a timestamp number
'format'returns a string formatted using pattern of format
token(MM/DD/YYYY)returns a string formatted using this pattern
shortcuts

the shortcuts for the range picker

[
  { text: 'today', onClick: () => new Date() },
  {
    text: 'Yesterday',
    onClick: () => {
      const date = new Date();
      date.setTime(date.getTime() - 3600 * 1000 * 24);
      return date;
    },
  },
];
AttributeDescription
texttitle of the shortcut
onClickcallback function , need to return a Date
time-picker-options

set fixed time list to select;

{start: '00:00', step:'00:30' , end: '23:30', format: 'HH:mm' }
AttributeDescription
startstart time
stepstep time
endend time
formatthe default is same as prop format

Events

NameDescriptionCallback Arguments
inputWhen the value change(v-model event)date
changeWhen the value change(same as input)date, type(date, hour, minute, second, ampm)
openWhen panel opening
closeWhen panel closing
confirmWhen click 'confirm' buttondate
clearWhen click 'clear' button
input-errorWhen user type a invalid Datethe input text
focusWhen input focus
blurWhen input blur
pickwhen select date #429date
calendar-changewhen change the calendardate, oldDate

Slots

NameDescription
icon-calendarcustom the calender icon
icon-clearcustom the clear icon
inputreplace input
headerpopup header
footerpopup footer
sidebarpopup sidebar

ChangeLog

CHANGELOG

License

MIT

Copyright (c) 2017-present xiemengxiong

Keywords

FAQs

Package last updated on 06 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc