1 Star 1 Fork 0

silas-liu / vue日历带农历

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

vue-lunar-full-calendar

NPM version NPM downloads

Image and demo

a vue component for lunar fullcalendar. Uses Moment.js for date operations.
Increase the functions of Chinese lunar calendar, 24 solar terms and holidays

Simple Live Demo Image text

Installation

npm install --save vue-lunar-full-calendar
//main.js
import LunarFullCalendar from "vue-lunar-full-calendar";
Vue.use(LunarFullCalendar);

But you can also import the standalone component to add locally or for more complex installations.

// index.vue
import { LunarFullCalendar } from "vue-lunar-full-calendar";
export default {
  components: {
    LunarFullCalendar
  }
};

Important function

1、window.lunar(date)

Use vue-lunar-full-calendar , You can use one function to get the date of a certain day.

2、lunarCalendar (default: true)

You can pass any custom options through to fullcalendar by using the config prop. Control whether the Chinese calendar shows true.

<lunar-full-calendar :events="events" :config="config"></lunar-full-calendar>
...
<script>
  ...
    data() {
      return {
        events: [],
        config: {
          lunarCalendar: true   //(Control whether the Chinese calendar shows true, unrealistic flase, default true.)
        },
      }
    },
  ...
    window.lunar(date)   // Date is the date.
  ...
</script>

Image text

API document

Fullcalendar 文档(Fullcalendar docs)

Example App

I have created a simple Vue 2 webpack application as an example/playground https://github.com/hjdev/vue-lunar-fullcalendar

Basic Usage

You can pass an array of fullclendar objects through the props

<lunar-full-calendar :events="events"></lunar-full-calendar> ...
<script>
  ...
    data() {
      return {
        events: [
          {
              title  : 'event1',
              start  : '2018-01-01',
          },
          {
              title  : 'event2',
              start  : '2018-01-05',
              end    : '2018-01-07',
          },
          {
              title  : 'event3',
              start  : '2018-01-09T12:30:00',
              allDay : false,
          },
        ]
      }
    }
  ...
</script>

More event options can be found at http://fullcalendar.io/docs/event_data/Event_Object/

Using a JSON Feed

<lunar-full-calendar :event-sources="eventSources"></lunar-full-calendar> ...
<script>
  ...
    data() {
      return {
        eventSources: [
          {
            events(start, end, timezone, callback) {
              self.$http.get(`/myFeed`, {timezone: timezone}).then(response => {
                callback(response.data.data)
              })
            },
            color: 'yellow',
            textColor: 'black',
          },
          {
            events(start, end, timezone, callback) {
              self.$http.get(`/anotherFeed`, {timezone: self.timezone}).then(response => {
                callback(response.data.data)
              })
            },
            color: 'red',
          },
        ]
      }
    }
  ...
</script>

Custom Config

You can pass any custom options through to fullcalendar by using the config prop, this includes extra event handlers.

<lunar-full-calendar :events="events" :config="config" /> ...
<script>
  ...
    data() {
      return {
        events: [],
        config: {
          weekends: false,
          drop(...args) {
            //handle drop logic in parent
          },
        },
      }
    },
  ...
</script>

Further Props

You can edit the look and feel of fullcalendar by passing through extra props. These all have sensible defaults

  • header - [obj] - docs
  • defaultView - ['agendaWeek'] - docs
  • editable - [true] - docs
  • selectable - [true] - docs
  • selectHelper - [true] - docs
  • config - [true] - Pass your own custom config straight through to fullcalendar

Methods

Sometimes you may need to manipulate the Calendar from your parent component, you can use fireMethod for this. This works with anything in the Fullcalendar docs suffixed with (method) and it will dynamically handle as many arguments as needed.

<lunar-full-calendar :events="events" ref="calendar" /> ...
<script>
  ...
    data() {
      return {
        events: [],
      }
    },

    methods: {
      next() {
        this.$refs.calendar.fireMethod('next')
      },
      changeView(view) {
        this.$refs.calendar.fireMethod('changeView', view)
      },
    },
  ...
</script>

Events and Hooks

Emitted

  • event-selected(event, jsEvent, view) - Triggered on eventClick()
  • event-drop(event) - Triggered on eventDrop()
  • event-resize(event) - Triggered on eventResize()
  • event-created(event) - Triggered on select()
  • event-receive(event) - Triggered on eventReceive()
  • event-render(event) - Triggered on eventRender()
  • day-click(date, jsEvent, view) - Triggered on dayClick()

You can listen for these events using the following markup

<lunar-full-calendar
  :event-sources="eventSources"
  @event-selected="eventSelected"
></lunar-full-calendar>

Listens on

  • render-event(event) - Adds a new event to calendar
  • remove-event(event) - Removes event from calendar
  • rerender-events() - Rerenders events to reflect local changes
  • refetch-events() - Makes another JSON call to event sources
  • reload-events() - Removes all events and adds all events in this.events

You can trigger these events in the parent component like so...

<lunar-full-calendar
  ref="calendar"
  :event-sources="eventSources"
></lunar-full-calendar>
...
<script>
  ...
    methods: {
      refreshEvents() {
        this.$refs.calendar.$emit('refetch-events')
      },
    }
  ...
</script>
MIT License Copyright (c) 2018 hj Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
JavaScript 等 5 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/silas-liu/vue-calendar-lunar.git
git@gitee.com:silas-liu/vue-calendar-lunar.git
silas-liu
vue-calendar-lunar
vue日历带农历
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891