Vue实现步骤条效果
作者:theMuseCatcher 发布时间:2024-04-28 10:54:23
标签:vue,步骤条
本文实例为大家分享了Vue实现步骤条效果的具体代码,供大家参考,具体内容如下
步骤总数和初始选择步骤 均可自定义设置,每个步骤title和description也均可自定义设置传入
效果图如下:
①创建步骤条组件Steps.vue:
<template>
<div class="m-steps-area">
<div class="m-steps">
<div
:class="['m-steps-item',
{ 'finished': current > 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)">
<div class="m-steps-icon">
<span class="u-icon" v-if="current<=n">{{ n }}</span>
<span class="u-icon" v-else>✓</span>
</div>
<div class="m-steps-content">
<div class="u-steps-title">{{ stepsLabel[n-1] || 'S ' + n }}</div>
<div class="u-steps-description">{{ stepsDesc[n-1] || 'Desc ' + n }}</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'Steps',
props: {
stepsLabel: { // 步骤title数组
type: Array,
default: () => {
return []
}
},
stepsDesc: { // 步骤description数组
type: Array,
default: () => {
return []
}
},
totalSteps: { // 总的步骤数
type: Number,
default: 3
},
currentStep: { // 当前选中的步骤
type: Number,
default: 1
}
},
data () {
return {
// 若当前选中步骤超过总步骤数,则默认选择步骤1
current: this.currentStep > this.totalSteps ? 1 : this.currentStep
}
},
methods: {
onChange (index) { // 点击切换选择步骤
console.log('index:', index)
if (this.current !== index) {
this.current = index
this.$emit('change', index)
}
}
}
}
</script>
<style lang="less" scoped>
.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);
}
}
}
}
}
</style>
②在要使用的页面引入Steps组件,并传入相关初始数据:
<Steps :currentStep="1" :totalSteps="3" :stepsLabel="stepsLabel" :stepsDesc="stepsDesc" @change="onChange" />
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)
}
}
来源:https://blog.csdn.net/Dandrose/article/details/119387366


猜你喜欢
- 设计单个页面,一点一点做就行了,但处理的页面多了,每个页面都一点点的做下去是非常费时费力的,特别是当许
- 又有人说设session.timeout=99999。这种同样不行,session有最大时间限制。我经过测试发现最大值为24小时,也就是说你
- 引言“深入认识Python内建类型”这部分的内容会从源码角度为大家介绍Python中各种常用的内建类
- 前言本文主要介绍的是利用python爬取京东商城的方法,文中介绍的非常详细,下面话不多说了,来看看详细的介绍吧。主要工具scrapyBeau
- 1、工作流程步骤(1)用spawn来执行一个程序;(2)用expect方法来等待指定的关键字,这个关键字是被执行的程序打印到标准输出上面的;
- Python中的函数调用与c++不同的是将this指针直接作为self当作第一个形参进行处理,从而将静态函数与实例方法的调用形式统一了起来。
- pytorch显存越来越多的一个原因optimizer.zero_grad()loss.backward()optimizer.step()
- Vision Transformer(VIT)Vision Transformer(ViT)是一种新兴的图像分类模型,它使用了类似于自然语言
- BLOB是一个大文件,典型的BLOB是一张图片或一个声音文件,由于它们的尺寸,必须使用特殊的方式来处理(例如:上传、下载或者存放到一个数据库
- 函数函数的英文单词是 Function,这个单词还有着功能的意思。在 Go 语言中,函数是实现某一特定功能的代码块。函数代表着某个功能,可以
- Entity Framework 4.0 也可以支持大名鼎鼎的MySql,这篇POST将向展示如何实现EF+MyS
- 发现错误利用Python库xlrd中的xlrd.open_workbook()函数读取自定义xlsx表格文件时出错如下:Traceback
- 我想从列表中取出一部分拿来使用,可以创建切片,指定需要使用的第一个元素和最后一个元素的索引使用例子,说明切片的使用#创建一个数字列表,代表我
- 当我们进行数据分析时,有时候需要对数值型数据进行离散化,将其划分为不同的标签或类别。这样做可以方便我们进行统计和分析,并帮助我们更好地理解数
- 我们都知道 vue 中可以使用 modal 来实现 input 内容数据的双向绑定。小程序好像没有提供相应的方法支持,就需要我们自己写了。原
- 散点图和折线图是数据分析中最常用的两种图形。其中,折线图用于分析自变量和因变量之间的趋势关系,最适合用于显示随着时间而变化的连续数据,同时还
- 需求每天往一个表里面插入两条数据,但日期不同INSERT INTO test(`id`, `art_training_institution
- 今天在继续学习Python时,打开Pycharm后,发现有一个项目下的项目文件名是红色的,如下图:刚开始我以为是我升级 Pycharm导致的
- 1. 准备工作有朋友可能没用过folium,它其实就是python的一个专业绘制地图的第三方库,所以在使用之前需要先安装它。pip 
- 测试用例我们分别在用户数据库(testpage),tempdb中创建相似对象t1,#t1,并在tempdb中创建创建非临时表,然后执行相应的