当前位置: 首页 > ops >正文

50天50个小项目 (Vue3 + Tailwindcss V4) ✨ | Progress Steps (步骤条)

📅 我们继续 50 个小项目挑战!—— Progress Steps 组件

仓库地址:https://github.com/SunACong/50-vue-projects
项目预览地址:https://50-vue-projects.vercel.app/

在这里插入图片描述

✨ 组件目标

  • 展示一个多步骤的进度条,指示当前所处的步骤

  • 提供“上一页”和“下一页”按钮,控制步骤的前进和后退

  • 动态更新进度条的长度和步骤的样式

🧱 技术实现点

使用 Vue 3 的 Composition API 和 ref 实现响应式状态管理

通过 v-for 渲染步骤列表

利用 Tailwind CSS 的实用工具类,如 flextransitionbg-gray-200rounded-full

使用条件样式绑定 :class 实现步骤的动态样式

🔧 ProgressSteps.vue 组件实现

<template><div class="py-96"><div class="relative mx-auto flex max-w-2/3 items-center justify-between"><div class="absolute z-0 h-2 w-full rounded-full bg-gray-200"><div:style="{ width: `${(current / (steps.length - 1)) * 100}%` }"class="absolute top-0 bottom-0 left-0 h-full rounded-full bg-blue-500 transition-all duration-300 ease-in-out"></div></div><divv-for="item in steps":key="item":class="['z-10 flex h-10 w-10 items-center justify-center rounded-full border-2 transition-all duration-500 ease-in-out',item.id - 1 <= current ? 'bg-blue-500 text-white' : 'bg-white',]">{{ item.id }}</div></div><div class="mt-10 flex items-center justify-center gap-20 text-white"><button:class="[current === 0 ? 'cursor-not-allowed opacity-50' : 'cursor-pointer']"class="rounded-2xl border-2 p-2 active:scale-90"@click="update('prev')":disabled="current === 0">prev</button><button:class="[current === steps.length - 1? 'cursor-not-allowed opacity-50': 'cursor-pointer',]"class="rounded-2xl border-2 p-2 active:scale-90"@click="update('next')":disabled="current === steps.length - 1">next</button></div></div>
</template><script setup>
import { ref } from 'vue'const current = ref(0)const steps = ref([{ id: 1 },{ id: 2 },{ id: 3 },{ id: 4 },{ id: 5 },{ id: 6 },{ id: 7 },{ id: 8 },{ id: 9 },{ id: 10 },
])const update = (type) => {if (type === 'prev') {if (current.value > 0) {current.value--}} else {if (current.value < steps.value.length - 1) {current.value++}}
}
</script>

💡 Tailwind CSS 样式重点讲解

类名功能描述
flex创建弹性布局
max-w-2/3设置最大宽度为容器的 2/3
rounded-full设置圆角为全圆
bg-gray-200 / bg-blue-500设置背景颜色
transition-all duration-500添加过渡动画效果
cursor-not-allowed设置鼠标样式为不可点击
opacity-50设置透明度为 50%
active:scale-90设置点击时缩放效果

🦌 常量定义 + 组件路由

  • constants/index.js 添加组件预览常量:
export const projectList = [{id: 2,title: 'Progress Steps',image: 'https://50projects50days.com/img/projects-img/2-progress-steps.png',link: 'ProgressSteps',},
]
  • router/index.js 中添加路由选项:
{path: '/ProgressSteps',name: 'ProgressSteps',component: () => import('@/projects/ProgressSteps.vue'),
}

🚀 小结

  • 使用 ref 管理当前步骤状态

  • 通过 v-for 渲染步骤列表

  • 使用条件样式绑定实现动态样式

  • 利用 Tailwind CSS 的实用工具类快速构建 UI

📅 明日预告:Rotating Navigation!实现旋转导航菜单组件。


每天进步一点点,50 天后惊艳所有人!

http://www.xdnf.cn/news/7251.html

相关文章:

  • Windows环境安装LibreOffice实现word转pdf
  • Python----目标检测(PASCAL VOC数据集)
  • 艾默生流量计与Profibus DP主站转Modbus RTU/TCP网关通讯案例
  • Linux利用多线程和线程同步实现一个简单的聊天服务器
  • 数据库中的属性列数和元组
  • Java POJO接收前端null值设置
  • java+selenium专题->启动浏览器下篇
  • 1.portainer
  • Unity editor文件数UI(支持勾选框)
  • 从 Word2Vec 到 BERT:AI 不止是词向量,更是语言理解
  • 带你搞懂@Valid和@Validated的区别
  • 【Go】从0开始学习Go
  • 【成品设计】基于Arduino的自动化农业灌溉系统
  • 基于DeepSeek的智能客服系统实践与创新
  • 【硬核数学】2. AI如何“学习”?微积分揭秘模型优化的奥秘《从零构建机器学习、深度学习到LLM的数学认知》
  • Java线程:多任务进行
  • 鸿蒙 Location Kit(位置服务)
  • 蓝桥杯1447 砝码称重
  • Flink 快速入门
  • 【LeetCode】大厂面试算法真题回忆(93)--优雅数组
  • 几种数据加密方法
  • 践行“科学智能”!和鲸打造 AI for Science 专属应用
  • docker安装Prometheus+Grafana
  • python如何遍历postgresql所有的用户表
  • OpenHarmony外设驱动使用 (五),Fingerprint_auth
  • ubuntu22.04 卸载ESP-IDF
  • AIGC与数字金融:人工智能金融创新的新纪元
  • [Java][Leetcode middle] 151. 反转字符串中的单词
  • Dify-3:系统架构
  • 国产 iPaaS 与国外 iPaaS 产品相比如何?以谷云科技为例