Vue3+Element-Plus || el-calendar考勤日历

element官网
其实就是官网上的代码,做了一点注释和小改动,这个基础上可以实现行程日历,打卡日历,活动日历等等。基本思想就是 <el-calendar>内你可以放n个<template>,日历放在#header插槽内,额外内容放在#date-cell插槽内。这个额外内容就正常写就行。
在这里插入图片描述
数据我只写了几个模拟数据。

<template>
    <div class="Calendarbox">
        <el-calendar ref="calendar" v-mobel="value">
            <!-- <template v-slot:header> this父组件,把这段template放在子组件的header插槽里-->
            <!-- 作用域插槽. -->
            <template #header="{ date }">
                <div class="leftbutton">
                    <el-button size="small" @click="selectDate('prev-year')">
                        <span>&lt&lt</span>
                    </el-button>
                    <el-button size="small" @click="selectDate('prev-month')">
                        <span>&lt</span>
                    </el-button>
                </div>
                <div class="middlebutton">
                    <el-button size="small" @click="selectDate('today')">
                        {{ date }}
                    </el-button>
                </div>
                <div class="rightbutton">
                    <el-button size="small" @click="selectDate('next-month')">
                        &lt
                    </el-button>
                    <el-button size="small" @click="selectDate('next-year')">
                        &lt&lt
                    </el-button>
                </div>
            </template>
            <!-- 通过设置名为 date-cell 的 scoped-slot 来自定义日历单元格中显示的内容。 在 scoped-slot 可以获取到 date(当前单元格的日期), data(包括 type,isSelected,day 属性)。 -->
            <template #date-cell="{ data }">
                <div style="display: flex;flex-direction: row;">
                    <div>
                        {{ data.day.split("-").slice(2).join("-") }}
                    </div>
                    <div v-for="i in kaoqin">
                        <div v-if="data.day.split('-').slice(2)==i.day">
                            <div>
                                <span :class="Wcolors.Wcolor(i.state[0])">{{i.state[0]}}</span>
                            </div>
                            <div>
                                <span :class="Wcolors.Wcolor(i.state[1])">{{i.state[1]}}</span>
                            </div>
                        </div>
                    </div>
                </div>
            </template>
        </el-calendar>
    </div>
</template>

<script setup>
/**
 * 组件 - 考勤日历(动态加载数据)
 */
import { ref } from 'vue';
import { kaoqin } from '../assets/MNdata/KQData.js';
import Wcolors from '../assets/MNdata/KQData.js';
//别名.(方法)

const calendar = ref()
const selectDate = (val) => {
    calendar.value.selectDate(val)
}
</script>
以下是使用Vue 3.0+Element-Plus开发后台管理系统的步骤: 1.首先,确保你已经安装了Node.js和npm包管理器。 2.使用以下命令安装Vue CLI 4: ```shell npm install -g @vue/cli ``` 3.使用Vue CLI创建一个新项目: ```shell vue create my-project ``` 4.在创建项目时,选择使用Vue 3.0版本,并启用class-style component语法: ```shell ? Please pick a preset: Manually select features ? Check the features needed for your project: Choose Vue version, Babel, Router, Vuex, CSS Pre-processors, Linter, Unit ? Choose a version of Vue.js that you want to start the project with 3.x (Preview) ? Use class-style component syntax? Yes ? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)? No ? Use history mode for router? (Requires proper server setup for index fallback in production) Yes ? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with dart-sass) ? Pick a linter / formatter config: ESLint with error prevention only ? Pick additional lint features: Lint on save ? Where do you prefer placing config for Babel, ESLint, etc.? In dedicated config files ``` 5.安装Element-Plus和Echarts 5.0: ```shell npm install element-plus echarts@5.0 ``` 6.在main.js中引入Element-Plus和Echarts: ```javascript import { createApp } from 'vue' import App from './App.vue' import router from './router' import store from './store' import ElementPlus from 'element-plus' import 'element-plus/lib/theme-chalk/index.css' import echarts from 'echarts' const app = createApp(App) app.use(store) app.use(router) app.use(ElementPlus) app.config.globalProperties.$echarts = echarts app.mount('#app') ``` 7.现在你可以开始使用Element-Plus和Echarts来开发你的后台管理系统了。
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值