vue2 实现日历组件,包含新增日程

实现的最终效果:
在这里插入图片描述

模板 html 部分

<template>
  <!-- 自定义提示组件 -->
  <div class="publicDialog">
    <el-dialog
      :visible.sync="Dialogshow"
      title="课程表"
      width="1050px"
      @open="open"
      @close="close"
      left
      :close-on-click-modal="false"
    >
      <div class="contentBody">
        <div class="flex-row-center">
          添加:
          <el-date-picker
            style="width: 210px"
            v-model="editForm.time"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-M-d"
          >
          </el-date-picker>
          <el-select
            v-model="editForm.type"
            style="width: 150px; margin-left: 14px"
            placeholder="请选择分类"
          >
            <el-option
              v-for="item in cateOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <el-input
            style="width: 310px; margin-left: 14px"
            v-model="editForm.txt"
            placeholder="请输入内容"
          ></el-input>
          <div
            style="margin-left: 20px"
            class="commonBtn width90Height36 borderRadius18 defalutBorderBtn"
            @click="cancleHandle"
          >
            取消
          </div>
          <div
            style="margin-left: 12px"
            class="commonBtn width90Height36 borderRadius18 hasBgBtn"
            @click="addConfirm"
          >
            确定
          </div>
        </div>
        <div class="air-calendar-box">
          <table class="sn-calendar-table">
            <thead>
              <i class="el-icon-arrow-left iconBtn" @click="preTimeHandle"></i>
              <th
                class="fc-day-header"
                v-for="(item, inx) in weekdays"
                :key="inx"
              >
                {
  { item }}
              </th>
              <i
                class="el-icon-arrow-right iconBtn"
                @click="nextTimeHandle"
              ></i>
            </thead>
            <tbody>
              <tr v-for="(calc, index1) in visibleTimetableData" :key="index1">
                <td
                  v-for="(item, idx) in calc"
                  :key="idx"
                  :class="{
                    include: item.include,
                    active: activeData && item.date === activeData.date,
                  }"
                  @click="clickDay(item)"
                >
                  <slot name="day" :row="item">
                    <div>
                      <div
                        class="month"
                        v-if="item.day2 == '01' || (index1 == 0 && idx == 0)"
                      >
                        {
  { item.month }}月
                      </div>
                      <div class="day">
                        {
  { item.day2 }}
                      </div>
                      <div style="
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于自定义月日历日程组件,你可以使用Vue.js框架来实现。下面是一个简单的示例代码,可以帮助你开始构建这个组件: ```vue <template> <div class="calendar"> <div class="header"> <button @click="previousMonth"><</button> <h2>{{ currentMonth }}</h2> <button @click="nextMonth">></button> </div> <div class="days"> <div v-for="day in days" :key="day" class="day">{{ day }}</div> </div> <div class="events"> <div v-for="event in events" :key="event.id" class="event"> <p>{{ event.date }}</p> <p>{{ event.title }}</p> </div> </div> </div> </template> <script> export default { data() { return { currentMonth: '', days: [], events: [ { id: 1, date: '2022-01-05', title: 'Event 1' }, { id: 2, date: '2022-01-15', title: 'Event 2' }, { id: 3, date: '2022-01-20', title: 'Event 3' }, ], }; }, mounted() { this.setCurrentMonth(); this.setDays(); }, methods: { setCurrentMonth() { const date = new Date(); const options = { month: 'long', year: 'numeric' }; this.currentMonth = date.toLocaleDateString('en-US', options); }, setDays() { const date = new Date(); const year = date.getFullYear(); const month = date.getMonth(); const daysInMonth = new Date(year, month + 1, 0).getDate(); this.days = Array.from({ length: daysInMonth }, (_, index) => index + 1); }, previousMonth() { // 实现切换到上一个月的逻辑 }, nextMonth() { // 实现切换到下一个月的逻辑 }, }, }; </script> <style> .calendar { /* 样式 */ } .header { /* 样式 */ } .days { /* 样式 */ } .day { /* 样式 */ } .events { /* 样式 */ } .event { /* 样式 */ } </style> ``` 这个例子中的日历组件包含一个头部,显示当前月份,以及上一个月和下一个月的按钮。接下来是一个天数的区域,以及事件的区域。你可以根据自己的需求来自定义样式。 这个示例中的事件是固定的,你可以根据你的具体需求从后端获取事件数据,并在`events`数组中进行动态渲染。 在`previousMonth`和`nextMonth`方法中,你可以实现切换到上一个月和下一个月的逻辑,例如更新`currentMonth`和`days`数据,以及获取新月份的事件数据。 希望这个示例能帮到你!如果有任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值