Under everyone’s urging, day after day, vuE3 – Hash – Calendar was finally born today.

As usual, renderings first

Demo

Please view it in mobile mode in your browser: www.hxkj.vip/demo/calend…

  • 🎉 feel good can give a star oh ~~ 🎉

The warehouse address

  • Github:github.com/TangSY/vue3…
  • Gitee: gitee.com/HashTang/vu…

Other versions

  • Vue 2.x version: github.com/TangSY/vue-…
  • React version: github.com/TangSY/reac…

vue3-hash-calendar

  • Calendar component developed based on Vue 3.X
  • Support gesture sliding operation
  • Native JS development, no third party library introduced
  • Supports fast switching between year and month
  • Swipe up and down to switch to weekly/monthly mode

    [Week mode] Slide left and right to switch to last week/next week [Month mode] Slide left and right to switch to last month/next month

Installation instructions

npm i -S vue3-hash-calendar

// In the import file (main.js), import the component library
import vueHashCalendar from 'vue3-hash-calendar'
// Introduce component CSS styles
import 'vue3-hash-calendar/lib/style.css'
const app = createApp(App);
// Register the component library
app.use(vueHashCalendar);
Copy the code
// Import components in VUE files
<vue-hash-calendar />
Copy the code

CDN import

// Add the following two CDN links to index.html:Js CDN: HTTPS://cdn.jsdelivr.net/npm/vue3-hash-calendar@{version}/lib/vue-hash-calendar.umd.js
css CDN: https://cdn.jsdelivr.net/npm/vue3-hash-calendar@{version}/lib/style.css

// Then in the WebPack configuration, add the following configuration.
externals: {
'vue-hash-calendar': 'VueHashCalendar'
},
Copy the code

API

attribute instructions type The default Whether will pass
visible To control the display or hiding of calendar components, usev-model:visible Boolean false no
scrollChangeDate Controls whether to change the selected date while sliding Boolean true no
model In what form the calendar component is displayed. Inline: inline mode. Dialog: mode of popup String inline no
defaultDatetime Specify the default time. Date The current time no
minDate Specifies the minimum date range in which the calendar can be slid. Date no
maxDate Specifies the maximum date range for a calendar that can only be swiped within. Date no
format The date format returned by the callback event when the date is confirmed. For example, “YY/MM/DD hh: MM”, “DD day of YY month, current time hh MM minute”, “MM DD,YY at hh: MM F” String YY/MM/DD hh:mm no
weekStart The day of the week starts each week of the calendar. Optional [‘ Sunday ‘, ‘Monday ‘,’ Tuesday ‘, ‘Wednesday ‘,’ Thursday ‘, ‘Friday ‘,’ Saturday ‘] String sunday no
pickerType Selector type DateTime: date + time Date: time Time: time String datetime no
showTodayButton Whether to display the back today button Boolean true no
isShowWeekView Specifies whether to display groups in a weekly viewv-model:isShowWeekViewa Boolean false no
isShowArrow Whether to display the week-month switch arrow (the small arrow below the calendar) when Model is equal to inline Boolean false no
isShowAction Whether to display the calendar component action bar (title bar) Boolean true no
isShowNotCurrentMonthDay Whether to display non-current month dates in the calendar (dates in gray) Boolean true no
disabledWeekView Disable week view (can’t slide up or down to switch week/month when set to true) Boolean false no
disabledDate Set the disabled status of the date with the current date, requiring Boolean to be returned (true to disable the date) Function no
disabledTime Set time to be disabled with the current date, Boolean required (True to disable time) Function no
disabledScroll Set the forbidden sliding direction of the calendar. Optional [‘left’, ‘right’, ‘up’, ‘down’, ‘horizontal’, ‘vertical’, true, false]. Take one of them to control a single direction in whichtrue å’Œ falseControl all directions. Boolean, String false no
markDate The dates that need to be marked can be grouped by different colors and different types of marks (blue is the default if no marks are grouped). Such as: [{color: ‘red’, date: [‘ 2019/02/25]}, {color: ‘blue’, type: ‘dot’ date: [‘ 2019/01/20]}, ‘2019/03/20] Array [] no
markType Dot: small dots (small dots below the date) Circle: small circles (the date is surrounded by small circles) dot+circle: use both small dots and circles String dot no
minuteStep Interval time. (Steps in minutes) Number 1 no
lang The selected language version. Optional values :[‘CN’, ‘EN’] String CN no
changeYearFast Whether to quickly switch the year by clicking the date area in the action bar (title bar) Boolean false no
themeColor Used to modify the calendar theme color { ‘main-color’: string; ‘bg-color’: string; ‘main-font-color’: string; ‘vice-font-color’: string; ‘disabled-bg-color’: string; ‘disabled-font-color’: string; } no
disabledClassName ClassName when the date is disabled. Use to modify the default style when the date is disabled String no
notCurrentMonthDayClassName A className that is not the date of the current display month (for example, the first and last days of the calendar in gray). Use to modify the default style for dates other than the current display month String no
checkedDayClassName ClassName when the date is selected. Use to modify the default style when the date is selected String no
todayClassName ClassName of the current date. Used to modify the default style of the current date String no
firstDayOfMonthClassName ClassName on the first day of the month. Use to modify the default style for the first day of the month String no

The event

The name of the event instructions parameter
change This event is triggered when the date changes. (The date format returned depends on the format attribute.) (date: the selected date when the date is changed)
confirm The event is triggered when the confirm button is clicked, and the button is present in dialog mode. (The date format returned depends on the format attribute.) (Date: the selected date when you click ok)
click This event is triggered when a date is clicked. (The date format returned depends on the format attribute.) (Date: current click date)
touchstart Calendar slide start event, same as native event. (Event: Touch event)
touchmove Calendar slide move event, same as native event. (Event: Touch event)
touchend Calendar slide end event, same as native event. (Event: Touch event)
slidechange Calendar slide direction. Return values: right, left, UP, down. (Direction: sliding direction)
calendarTypeChange Triggered when the calendar display type is switched. Returned values: Date, month, year, yearRange. (Type: calendar display panel type)

Slot Slot.

name instructions
day Custom date content. For example can be used to add lunar calendar and so on. With custom className use, the effect is better! The parameter is {date, extendAttr}, where extendAttr parameter containsisMarked(Whether the date is marked),isDisabledDate(Whether the date is disabled),isToday(Whether the date is today),isChecked(whether the date is selected),isCurrentMonthDay(whether the date is the date of this month),isFirstDayOfMonth(whether the date is the first day of the month), can be used for some special needs
week Custom week content. For example, it can be used to customize the style of the week and so on. Parameter {week}
arrow Customize the indicator arrow when switching between week and month. The parameter is {show},show: Boolen, which indicates whether the current view is a weekly view
today Custom “Today” button text content and style
confirm Custom “OK” button text content and style
action Customize action bar (title bar) content and style

Method

Method names instructions
lastMonth Switch calendar to previous month
nextMonth Switch the calendar to the next month
lastWeek Switch calendar to previous week
nextWeek Switch the calendar to the next week
today Return to today. When disabled today, it does not take effect

Other

  • How do I display the calendar component in Dialog mode? Pay attention to usev-model:visible
<vue-hash-calendar v-model:visible="isShowCalendar"></vue-hash-calendar>

// Set to true
this.isShowCalendar = true;
Copy the code
  • CDN introduced components, why some attributes do not work?
In non-Webpack development mode, attribute names cannot be humped. For example, write isShowAction as is-show-action.Copy the code
  • If you want to return a standard English format date, how should you write the format attribute?MM DD,YY at hh:mm F
<vue3-hash-calendar format="MM DD,YY at hh:mm F" />
Copy the code
  • If you want to return a 12-hour date, how should you write the format attribute? Uppercase the formatting stringF
<vue3-hash-calendar format="YY/MM/DD hh:mm F" />
Copy the code
  • Basic usage of day slot
https://github.com/TangSY/vue3-hash-calendar/blob/dev/examples/FirstDayDemo.vue

Copy the code
  • Can be triggered by an external button to expand and close the calendar
You can control the collapse and expansion of the calendar externally by changing the value of isShowWeekViewCopy the code
  • How do I set the disable date? Refer to the source codeApp.vuefile
For example, disable all dates before today

/** Vue template file **/
<vue-hash-calendar :disabled-date="disabledDate"></vue-hash-calendar>

/** Vue methods **/
disabledDate(date) {
    let timestamp = date.getTime();
    if (timestamp > new Date().getTime()) {
        return true
    }

    return false
}
Copy the code
  • How do I set the disable date? Refer to the source codeApp.vuefile
// For example, disable the time before now

/** Vue template file **/
<vue-hash-calendar :disabled-time="disabledTime"></vue-hash-calendar>

/** Vue methods **/
disabledTime(date) { // Disable time
  let hours = date.getHours()
  let minute = date.getMinutes()
  let hoursNow = new Date().getHours()
  let minuteNow = new Date().getMinutes()

  if (hours < hoursNow || (hours === hoursNow && minute < minuteNow)) {
    return true
  }
  return false
}
Copy the code

conclusion

Author: HashTang

Personal Space: HXKJ.VIP

Friends passing by, in the nuggets massive article library, can have the honor to come in and see here, thank you very much!

Don’t forget to like, follow, comment and support

If there are other problems, or functional incompatibilities. You can email [email protected] or submit an issue on Github.