当前位置:首页 > VUE

vue实现打卡进度组件

2026-01-23 09:39:48VUE

Vue 打卡进度组件实现

核心思路
通过动态计算已完成天数与总天数的比例,结合 CSS 动画或过渡效果,实现进度条或日历形式的打卡可视化。

基础进度条实现

模板部分

<template>
  <div class="progress-container">
    <div class="progress-bar" :style="{ width: progress + '%' }"></div>
    <span>{{ progress }}% 已完成</span>
  </div>
</template>

脚本部分

<script>
export default {
  props: {
    totalDays: { type: Number, default: 30 },
    completedDays: { type: Number, default: 0 }
  },
  computed: {
    progress() {
      return Math.round((this.completedDays / this.totalDays) * 100);
    }
  }
};
</script>

样式部分

<style scoped>
.progress-container {
  width: 100%;
  height: 20px;
  background-color: #f0f0f0;
  border-radius: 10px;
  position: relative;
}
.progress-bar {
  height: 100%;
  background-color: #4caf50;
  border-radius: 10px;
  transition: width 0.3s ease;
}
</style>

日历打卡形式实现

模板部分

<template>
  <div class="calendar-grid">
    <div 
      v-for="day in totalDays" 
      :key="day" 
      class="day-cell"
      :class="{ 'completed': day <= completedDays }"
    ></div>
  </div>
</template>

样式部分

<style scoped>
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}
.day-cell {
  width: 30px;
  height: 30px;
  background-color: #e0e0e0;
  border-radius: 4px;
}
.day-cell.completed {
  background-color: #4caf50;
}
</style>

动画增强效果

添加点击动画
在日历形式中增加点击反馈:

.day-cell {
  transition: transform 0.2s;
}
.day-cell:active {
  transform: scale(0.9);
}

进度条加载动画

.progress-bar {
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.7; }
  100% { opacity: 1; }
}

进阶功能扩展

持久化存储
结合 localStorage 保存打卡状态:

mounted() {
  const savedProgress = localStorage.getItem('progress');
  if (savedProgress) {
    this.completedDays = parseInt(savedProgress);
  }
},
methods: {
  handleDayClick(day) {
    if (day === this.completedDays + 1) {
      this.completedDays++;
      localStorage.setItem('progress', this.completedDays);
    }
  }
}

节日特殊样式
通过日期判断添加特殊样式:

computed: {
  dayClass() {
    return (day) => ({
      'holiday': this.isHoliday(day),
      'completed': day <= this.completedDays
    });
  }
}

注意事项

  1. 移动端适配需调整单元格大小和间距
  2. 国际化场景需动态显示周数/月份
  3. 大量天数时建议使用虚拟滚动优化性能
  4. 颜色方案可通过 CSS 变量实现主题切换

以上实现可根据实际需求组合使用,例如同时显示进度条和日历,或添加徽章奖励等激励元素。

vue实现打卡进度组件

标签: 进度组件
分享给朋友:

相关文章

vue实现组件封装

vue实现组件封装

Vue 组件封装方法 封装组件的基本步骤 创建独立的 .vue 文件,包含 template、script 和 style 三个部分。通过 props 接收父组件传递的数据,使用 $emit 触发…

vue动态组件实现

vue动态组件实现

Vue 动态组件实现方法 使用 component 标签与 is 属性 通过 Vue 内置的 <component> 标签和 is 属性实现动态组件切换。is 的值可以是已注册的组件名或导…

vue实现tooltips组件

vue实现tooltips组件

Vue实现Tooltips组件的方法 基础实现:使用Vue指令 创建一个自定义指令v-tooltip,通过鼠标事件触发提示框的显示与隐藏。 Vue.directive('tooltip', {…

vue实现组件循环

vue实现组件循环

Vue 实现组件循环的方法 在 Vue 中,可以通过 v-for 指令实现组件的循环渲染。以下是几种常见的实现方式: 使用 v-for 渲染数组 通过 v-for 遍历数组数据,动态生成组件列表:…

vue实现组件循环图片

vue实现组件循环图片

Vue 实现组件循环图片的方法 在 Vue 中实现组件循环图片通常可以通过 v-for 指令结合动态数据绑定完成。以下是几种常见的实现方式: 使用静态图片路径数组 假设有一组本地图片路径,可以通过数…

实现vue组件

实现vue组件

创建 Vue 组件 Vue 组件可以通过单文件组件(.vue 文件)或直接在 JavaScript 中定义。以下是两种常见实现方式。 单文件组件方式 单文件组件包含模板、脚本和样式三部分,适合复杂…