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

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 天后惊艳所有人!

相关文章:

  • redis的List为什么用ziplist和quicklist
  • GitHub 趋势日报 (2025年05月18日)
  • 学习记录:DAY29
  • 【HTML-1】HTML骨架标签:构建网页的基础框架
  • 百度OCR:证件识别
  • 【信息系统项目管理师】第10章:项目进度管理 - 48个经典题目及详解
  • 十三、面向对象底层逻辑-Dubbo序列化Serialization接口
  • React组件开发流程-03.1
  • 双指针算法:原理与应用详解
  • Notepad++ 学习(三)使用python插件编写脚本:实现跳转指定标签页(自主研发)
  • 龙芯中科2024年度业绩说明会:企稳向好,布局未来!
  • 抽奖相关功能测试思路
  • NIFI的处理器:PutDatabaseRecord 2.4.0
  • 【数据仓库面试题合集③】实时数仓建模思路与实践详解
  • C++_AVL树
  • 从API到UI:直播美颜SDK中的滤镜与贴纸功能开发与落地方案详解
  • 打破传统仓库管理困局:WMS如何重构出入库全流程
  • 告别Spring AI!我的Java轻量AI框架实践(支持多模型接入|注解式MCP架构|附开源地址)
  • 【框架安装】win10 配置安装GPU加速的tensorflow和keras教程
  • 3D 数据交换格式(.3DXML)简介
  • 新疆巴音郭楞州和硕县发生4.6级地震,震源深度10千米
  • 去年中企海外新增风电装机量5.4GW,亚太区域占比过半
  • “打铁”热邂逅江南水乡,长三角首个国际级铁三赛事有何不同
  • 中国旅游日|上天当个“显眼包”!低空经济的“飞”凡魅力
  • 定制基因编辑疗法治愈罕见遗传病患儿
  • 艺术稀缺性和价值坚守如何构筑品牌差异化壁垒?从“心邸”看CINDY CHAO的破局之道