当前位置:首页 > VUE

vue实现日程

2026-01-12 11:58:47VUE

Vue 实现日程功能的方法

使用 FullCalendar 插件

FullCalendar 是一个功能强大的日历插件,支持 Vue 集成。安装依赖:

npm install @fullcalendar/vue @fullcalendar/core @fullcalendar/daygrid @fullcalendar/interaction

在 Vue 组件中引入并配置:

vue实现日程

<template>
  <FullCalendar :options="calendarOptions" />
</template>

<script>
import FullCalendar from '@fullcalendar/vue'
import dayGridPlugin from '@fullcalendar/daygrid'
import interactionPlugin from '@fullcalendar/interaction'

export default {
  components: { FullCalendar },
  data() {
    return {
      calendarOptions: {
        plugins: [dayGridPlugin, interactionPlugin],
        initialView: 'dayGridMonth',
        events: [
          { title: '会议', start: '2023-10-01' },
          { title: '截止日期', start: '2023-10-15' }
        ],
        dateClick: this.handleDateClick
      }
    }
  },
  methods: {
    handleDateClick(arg) {
      alert('点击日期: ' + arg.dateStr)
    }
  }
}
</script>

自定义日程组件

通过原生 Vue 实现简单的日程视图:

<template>
  <div class="calendar">
    <div v-for="day in days" :key="day.date" class="day">
      <div class="date">{{ day.date }}</div>
      <div v-for="event in day.events" :key="event.id" class="event">
        {{ event.title }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      days: [
        { date: '2023-10-01', events: [{ id: 1, title: '团队会议' }] },
        { date: '2023-10-02', events: [] }
      ]
    }
  }
}
</script>

<style>
.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.day {
  border: 1px solid #eee;
  padding: 8px;
}
.event {
  background: #e3f2fd;
  margin: 4px 0;
  padding: 4px;
}
</style>

与后端数据交互

结合 API 获取日程数据:

vue实现日程

methods: {
  async fetchEvents() {
    try {
      const response = await axios.get('/api/events')
      this.calendarOptions.events = response.data
    } catch (error) {
      console.error('获取日程失败:', error)
    }
  }
},
mounted() {
  this.fetchEvents()
}

添加日程功能

实现新增日程的交互:

<template>
  <button @click="showDialog = true">添加日程</button>
  <dialog v-if="showDialog">
    <input v-model="newEvent.title" placeholder="事件标题">
    <input type="date" v-model="newEvent.date">
    <button @click="addEvent">保存</button>
  </dialog>
</template>

<script>
export default {
  data() {
    return {
      showDialog: false,
      newEvent: { title: '', date: '' }
    }
  },
  methods: {
    addEvent() {
      this.events.push({ ...this.newEvent })
      this.showDialog = false
      this.newEvent = { title: '', date: '' }
    }
  }
}
</script>

实现拖拽功能

使用 Vue.Draggable 实现日程项拖拽排序:

npm install vuedraggable
<template>
  <draggable v-model="events" group="events">
    <div v-for="event in events" :key="event.id" class="event">
      {{ event.title }}
    </div>
  </draggable>
</template>

<script>
import draggable from 'vuedraggable'
export default {
  components: { draggable }
}
</script>

标签: 日程vue
分享给朋友:

相关文章

用vue实现搜索查询

用vue实现搜索查询

实现搜索查询的基本思路 在Vue中实现搜索查询功能通常涉及以下几个核心部分:数据绑定、事件监听、过滤逻辑和UI反馈。以下是一个完整的实现方案。 数据绑定与输入框 创建一个Vue组件,包含一个输入框用…

vue实现管道

vue实现管道

Vue 中实现管道(Pipe)功能 在 Vue 中可以通过过滤器(Filters)或计算属性(Computed Properties)实现类似管道的功能,将数据经过多个处理步骤后输出。 使用过滤器(…

vue实现drag

vue实现drag

Vue 实现拖拽功能的方法 在 Vue 中实现拖拽功能可以通过原生 HTML5 的拖拽 API 或第三方库如 vuedraggable 来完成。以下是两种常见方法的实现方式。 使用 HTML5 拖拽…

vue实现批量

vue实现批量

Vue 实现批量操作的方法 在 Vue 中实现批量操作通常涉及选择多个项目并执行统一处理,例如批量删除、批量更新等。以下是几种常见实现方式: 表格多选批量操作 使用 el-table 配合复选框实…

vue 实现打印

vue 实现打印

Vue 实现打印功能的方法 在Vue项目中实现打印功能,可以通过以下几种方式实现: 使用window.print()方法 通过调用浏览器的原生打印API实现基础打印功能,适用于简单内容打印。 //…

vue实现弹幕

vue实现弹幕

Vue 实现弹幕功能 弹幕功能通常包括动态生成、滚动显示、颜色和速度随机化等特性。以下是基于 Vue 3 的实现方法。 核心思路 使用 CSS 动画控制弹幕从右向左滚动。 动态生成弹幕数据,随机设…