当前位置:首页 > 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 无限菜单的方法 递归组件实现嵌套菜单 使用 Vue 的递归组件特性可以轻松实现无限级嵌套菜单。通过组件调用自身的方式处理嵌套数据。 <template> <ul&…

vue实现倒计时抢券

vue实现倒计时抢券

Vue 实现倒计时抢券功能 核心逻辑 倒计时抢券功能需要结合时间计算、状态管理和界面交互。通过 Vue 的响应式特性和生命周期钩子,可以高效实现这一需求。 实现步骤 1. 数据准备 在 Vue 组件…

vue实现遮罩

vue实现遮罩

Vue 实现遮罩层的方法 在 Vue 中实现遮罩层可以通过多种方式完成,以下是几种常见的方法: 方法一:使用 v-show 或 v-if 控制显示 通过 Vue 的指令动态控制遮罩层的显示与隐藏。…

vue实现筛选

vue实现筛选

实现筛选功能的基本思路 在Vue中实现筛选功能通常需要结合数据绑定、计算属性和方法。筛选的核心逻辑是根据用户输入的条件过滤原始数据列表,并动态更新显示结果。 数据准备 定义一个数组存储原始数据,另一…

vue远离实现

vue远离实现

Vue 原理实现 Vue.js 的核心原理包括响应式系统、虚拟 DOM、模板编译和组件化机制。以下是其关键实现原理的详细解析。 响应式系统 Vue 的响应式系统基于 Object.definePro…

vue实现加载

vue实现加载

Vue 实现加载功能的方法 使用 v-if 或 v-show 控制加载状态 通过数据绑定控制加载动画的显示与隐藏。v-if 会完全移除 DOM 元素,v-show 只是切换 display 属性。…