Vue实现步骤条效果
本文实例为大家分享了Vue实现步骤条效果的具体代码,供大家参考,具体内容如下
步骤总数和初始选择步骤 均可自定义设置,每个步骤title和description也均可自定义设置传入
效果图如下:
文章图片
①创建步骤条组件Steps.vue:
n,'process': current === n && n !== totalSteps,'last-process': current === totalSteps && n === totalSteps,'middle-wait': current < n && n !== totalSteps,'last-wait': current < n && n === totalSteps,}]"v-for="n in totalSteps":key="n"@click="onChange(n)">{{ n }}?{{ stepsLabel[n-1] || 'S ' + n }}{{ stepsDesc[n-1] || 'Desc ' + n }}.m-steps-area {width: 1100px; margin: 0px auto; .m-steps {padding: 30px 0; display: flex; .m-steps-item {display: inline-block; flex: 1; // 弹性盒模型对象的子元素都有相同的长度,且忽略它们内部的内容overflow: hidden; font-size: 16px; line-height: 32px; .m-steps-icon {display: inline-block; margin-right: 8px; width: 32px; height: 32px; border-radius: 50%; text-align: center; }.m-steps-content {display: inline-block; vertical-align: top; padding-right: 16px; .u-steps-title {position: relative; display: inline-block; padding-right: 16px; }.u-steps-description {font-size: 14px; max-width: 140px; }}}.finished {margin-right: 16px; cursor: pointer; &:hover {.m-steps-content {.u-steps-title {color: #1890ff; }.u-steps-description {color: #1890ff; }}}.m-steps-icon {background: #fff; border: 1px solid rgba(0,0,0,.25); border-color: #1890ff; .u-icon {color: #1890ff; }}.m-steps-content {color: rgba(0,0,0,.65); .u-steps-title {color: rgba(0,0,0,.65); &:after {background: #1890ff; position: absolute; top: 16px; left: 100%; display: block; width: 9999px; height: 1px; content: ""; }}.u-steps-description {color: rgba(0,0,0,.45); }}}.process {margin-right: 16px; .m-steps-icon {background: #1890ff; border: 1px solid rgba(0,0,0,.25); border-color: #1890ff; .u-icon {color: #fff; }}.m-steps-content {color: rgba(0,0,0,.65); .u-steps-title {font-weight: 600; color: rgba(0,0,0,.85); &:after {background: #e8e8e8; position: absolute; top: 16px; left: 100%; display: block; width: 9999px; height: 1px; content: ""; }}.u-steps-description {color: rgba(0,0,0,.65); }}}.last-process {margin-right: 0; .m-steps-icon {background: #1890ff; border: 1px solid rgba(0,0,0,.25); border-color: #1890ff; .u-icon {color: #fff; }}.m-steps-content {color: rgba(0,0,0,.65); .u-steps-title {font-weight: 600; color: rgba(0,0,0,.85); }.u-steps-description {color: rgba(0,0,0,.65); }}}.middle-wait {margin-right: 16px; cursor: pointer; &:hover {.m-steps-icon {border: 1px solid #1890ff; .u-icon {color: #1890ff; }}.m-steps-content {.u-steps-title {color: #1890ff; }.u-steps-description {color: #1890ff; }}}.m-steps-icon {background: #fff; border: 1px solid rgba(0,0,0,.25); .u-icon {color: rgba(0,0,0,.25); }}.m-steps-content {color: rgba(0,0,0,.65); .u-steps-title {color: rgba(0,0,0,.45); &:after {background: #e8e8e8; position: absolute; top: 16px; left: 100%; display: block; width: 9999px; height: 1px; content: ""; }}.u-steps-description {color: rgba(0,0,0,.45); }}}.last-wait {margin-right: 0; cursor: pointer; &:hover {.m-steps-icon {border: 1px solid #1890ff; .u-icon {color: #1890ff; }}.m-steps-content {.u-steps-title {color: #1890ff; }.u-steps-description {color: #1890ff; }}}.m-steps-icon {background: #fff; border: 1px solid rgba(0,0,0,.25); .u-icon {color: rgba(0,0,0,.25); }}.m-steps-content {color: rgba(0,0,0,.65); .u-steps-title {color: rgba(0,0,0,.45); }.u-steps-description {color: rgba(0,0,0,.45); }}}}}
②在要使用的页面引入Steps组件,并传入相关初始数据:
import Steps from '@/components/Steps'components: {Steps},data () {return {stepsLabel: ['Step 1', 'Step 2', 'Step 3', 'Step 4', 'Step 5'],stepsDesc: ['description 1', 'description 2', 'description 3', 'description 4', 'description 5']}}methods: {onChange (index) { // 父组件获取切换后的选中步骤console.log('parentIndex:', index)}}
【Vue实现步骤条效果】以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
推荐阅读
- 关于Vue脚手架中render|关于Vue脚手架中render 理解
- vue3和react17(三)|vue3和react17(三) - 生命周期(ts)
- C语言|C语言实现——字符串逆序
- c语言|C语言——字符串分类统计
- vue 接收后端返回文件流下载操作
- 分布式|面试官(ZooKeeper分布式锁实现,你了解了吗())
- java|面试官(ZK(ZooKeeper)分布式锁实现,你了解了吗())
- 用python实现词云效果实例介绍
- Vue3+Nuxt3打造SSR网站应用,0到1实现服务端渲染吾爱fen享受
- 使用Go语言web框架wego实现用户登录功能