Vue2步骤条(Steps)

article/2025/9/17 23:44:54
  • Vue3步骤条(Steps)

  • 可自定义设置以下属性:

  • 步骤标题数组(stepsLabel)
  • 步骤描述数组(stepsDesc)
  • 步骤总数(totalSteps),默认3
  • 当前选中的步骤(currentStep),默认1
  • 步骤条总宽度(totalWidth),默认900px
  • 描述文本最大宽度(descMaxWidth),默认140px
  • 效果图如下:

 ​

①创建步骤条组件Steps.vue:

<template><div class="m-steps-area" :style="`width: ${totalWidth}px;`"><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"><div class="m-info-wrap" @click="onChange(n)"><div class="m-steps-icon"><span class="u-icon" v-if="current<=n">{{ n }}</span><svg class="u-icon" v-else viewBox="64 64 896 896" data-icon="check" aria-hidden="true" focusable="false"><path d="M912 190h-69.9c-9.8 0-19.1 4.5-25.1 12.2L404.7 724.5 207 474a32 32 0 0 0-25.1-12.2H112c-6.7 0-10.4 7.7-6.3 12.9l273.9 347c12.8 16.2 37.4 16.2 50.3 0l488.4-618.9c4.1-5.1.4-12.8-6.3-12.8z"></path></svg></div><div class="m-steps-content"><div class="u-steps-title">{{ stepsLabel[n-1] }}</div><div class="u-steps-description" v-show="stepsDesc[n-1]" :style="`max-width: ${descMaxWidth}px;`">{{ stepsDesc[n-1] }}</div></div></div></div></div></div>
</template>
<script>
export default {name: 'Steps',props: {stepsLabel: { // 步骤标题数组type: Array,default: () => {return []}},stepsDesc: { // 步骤描述数组type: Array,default: () => {return []}},totalSteps: { // 步骤总数type: Number,default: 3},currentStep: { // 当前选中的步骤type: Number,default: 1},totalWidth: { // 步骤条总宽度type: Number,default: 900},descMaxWidth: { // 描述文本最大宽度type: Number,default: 140}},data () {return {// 若当前选中步骤超过总步骤数,则默认选择步骤1current: this.currentStep > this.totalSteps ? 1 : this.currentStep}},methods: {onChange (index) { // 点击切换选择步骤// e.stopPropagation()console.log('index:', index)if (this.current !== index) {this.current = indexthis.$emit('change', index)}}}
}
</script>
<style lang="less" scoped>
@themeColor: #1890FF;
.m-steps-area {margin: 0px auto;.m-steps {padding: 30px 0;display: flex;.m-steps-item {display: inline-block;overflow: hidden;font-size: 16px;line-height: 32px;&:not(:last-child) {margin-right: 16px;flex: 1; // 弹性盒模型对象的子元素都有相同的长度,且忽略它们内部的内容}.m-info-wrap {display: inline-block;cursor: pointer;.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;.u-steps-title {position: relative;display: inline-block;padding-right: 16px;}.u-steps-description {font-size: 14px;word-wrap: break-word;}}}}.u-tail {background: #e8e8e8;position: absolute;top: 16px;left: 100%;display: block;width: 3000px;height: 1px;content: "";}.finished {&:hover {.m-steps-content {.u-steps-title {color: @themeColor;}.u-steps-description {color: @themeColor;}}}.m-steps-icon {background: #fff;border: 1px solid rgba(0,0,0,.25);border-color: @themeColor;.u-icon {fill: @themeColor;width: 16px;height: 16px;vertical-align: top;margin-top: 8px;}}.m-steps-content {color: rgba(0,0,0,.65);.u-steps-title {color: rgba(0,0,0,.65);&:after {.u-tail();background: @themeColor;}}.u-steps-description {color: rgba(0,0,0,.45);}}}.process {.m-steps-icon {background: @themeColor;border: 1px solid rgba(0,0,0,.25);border-color: @themeColor;.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 {.u-tail();}}.u-steps-description {color: rgba(0,0,0,.65);}}}.last-process {.m-steps-icon {background: @themeColor;border: 1px solid rgba(0,0,0,.25);border-color: @themeColor;.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 {&:hover {.m-steps-icon {border: 1px solid @themeColor;.u-icon {color: @themeColor;}}.m-steps-content {.u-steps-title {color: @themeColor;}.u-steps-description {color: @themeColor;}}}.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 {.u-tail();}}.u-steps-description {color: rgba(0,0,0,.45);}}}.last-wait {margin-right: 0;&:hover {.m-steps-icon {border: 1px solid @themeColor;.u-icon {color: @themeColor;}}.m-steps-content {.u-steps-title {color: @themeColor;}.u-steps-description {color: @themeColor;}}}.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="3":totalSteps="5":stepsLabel="stepsLabel":stepsDesc="stepsDesc":totalWidth="900":descMaxWidth="160"@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('current:', index)}
}

http://chatgpt.dhexx.cn/article/9fWBjhav.shtml

相关文章

Vue3步骤条(Steps)

Vue2步骤条&#xff08;Steps&#xff09; 可自定义设置以下属性&#xff1a; 步骤数组&#xff08;steps&#xff09;&#xff0c;类型&#xff1a;Array<{title?: string, description?: string}>&#xff0c;默认 [] 当前选中的步骤&#xff0c;设置 v-model 后&a…

CSS3动画——steps函数

CSS3动画中应用的定时函数&#xff08;timing function&#xff09;常用的有内置关键字linear, ease, ease-in, ease-out, ease-in-out, step-start, step-end&#xff0c;另外还有两个内置的缓动函数cubic-bezier(), steps() 其中steps()这个函数是将整个动画过程分为指定的步…

css3中animation的steps分步动画

css的animation中&#xff0c;有一种描述动画变化速率的东西&#xff0c;例如常见的linear,ease-in,ease-out等&#xff0c;这些都是连续的变化&#xff0c;还有一种叫做steps的&#xff0c;它用来描述一种不连续的动画&#xff0c;也就是逐帧动画。 基本认识 steps的格式为&…

超几何分布(Hypergeometric distribution)

超几何分布 百度解释 https://baike.baidu.com/item/超几何分布/4782968?fraladdin 通俗解释 超几何分布中的参数是M,N,n&#xff0c;超几何分布记作X~H(N,M,n) 。假如一共有100颗球&#xff0c;20颗为红球&#xff0c;80颗为白球&#xff0c;从中不放回地拿出10个球&#x…

机器学习小组知识点12:超几何分布(Hyper-Geometric Distribution)

超几何分布与二项分布的联系与区别 事实上,超几何分布和二项分布确实有着密切的联系&#xff0c;但也有明显的区别。   课本对于超几何分布的定义是这样的&#xff1a;一般的&#xff0c;若一个随机变量X的分布列为&#xff0c;其中&#xff0c;则称X服从超几何分布&#xf…

常见分布总结-高斯分布、伯努利分布、泊松分布、几何分布、beta分布

概率分布 概率分布是指用于表述随机变量取值的概率规律,包括连续分布和离散分布。 下面作了这些概率分布的一个思维导图。 文章目录 概率分布1、离散概率分布1.1、两点分布2.2、 二项分布1.3、几何分布1.4、超几何分布1.5、泊松分布2、连续概率分布2.1、均匀分布2.2、正太分布…

超几何分布的其他形式及其解释?

超几何分布定义 百度百科&#xff1a;超几何分布是统计学上一种离散概率分布。它描述了从有限N个物件&#xff08;其中包含M个指定种类的物件&#xff09;中抽出n个物件&#xff0c;成功抽出该指定种类的物件的次数&#xff08;不放回&#xff09;。称为超几何分布&#xff0c;…

geometric distribution and exponential distribution(几何分布和指数分布)

几何分布 分布函数均值和方差意义 表示经过k次实验才第一次得到正确的实验结果 比如抛硬币得到正面的需要抛的次数 指数分布 分布函数均值和方差意义 表示经过一段x之后&#xff0c;某件事第一次发生 比如经过x时间之后&#xff0c;公交车来的概率 比如餐厅从开业到第一个客人…

概率论的学习和整理9:超几何分布 (未完成!!!)

目录 1超几何分布 Hypergeometric distribution 1.1 超几何分布的定义 1.2 为什么叫超几何分布 1.3 超几何分布的公式 &#xff08;2种公式&#xff09; 1.3.1 超几何分布的公式1 &#xff08;总体型公式&#xff09; 1.3.2 超几何分布的公式2 &#xff08;拆…

概率论与数理统计基础(二):常用离散分布 二项、泊松、超几何分、几何、 负二项分布

本文列举了常见的离散分布&#xff0c;关于它们的背景、概率分布列、数学期望与方差&#xff0c;以及与之相关的一些重要性质&#xff1b;比如几何分布的无记忆性、 二项分布的泊松近似、超几何分布的二项近似。。。。可作为离散分布的知识速查表。 目录 1. 二项分布b(n,p) …

如何理解几何分布与指数分布的无记忆性?

在经济学上&#xff0c;有一个概念是沉没成本&#xff0c;大概指的是已经付出的、且不可收回的成本。针对这个概念有一个常见的说法&#xff1a; 这句话的意思是&#xff0c;既然沉没成本不可收回&#xff0c;那么在做选择的时候就不应该考虑它。举一个简单的例子&#xff0c;买…

几何分布的期望公式的推导

随机变量服从几何分布 概率分布 期望 现在先求等差比数列和 ②-③, 并运用等比数列求和公式,可得 将④代入①得

统计学:几何分布、二项分布、泊松分布

一、几何分布 假设某种赌博游戏的胜率为0.2&#xff0c;那么意味着你玩第一次就胜出的概率为0.2。 那玩第二次才胜出呢&#xff1f;“玩第二次才胜出”就意味着玩第一次是失败的&#xff0c;而直到第二次才胜出&#xff0c;那么这件事发生的概率就是0.80.20.16。 那么第三次…

统计学 分布篇 - Hypergeometric Distribution(超几何分布)

超几何分布: 是 离散随机分布的一种. 它描述的是 从 n 中 拿 k 个成功的事件的概率( 不放回, 不放回意味着该事件是非独立事件), 其中在 N 中一共有 K 个成功事件. n 为 样本数量, k 为样本中成功的概率 N为 事件的总数量(population), K为 在N中 事件的总数量. note: 超几…

几何分布的期望与方差

几何分布的期望与方差 高中数学教科书新版第三册&#xff08;选修II&#xff09;比原来的修订本新增加随机变量的几何分布&#xff0c;但书中只给出了结论&#xff1a;&#xff08;1&#xff09;&#xff0c;&#xff08;2&#xff09;&#xff0c;而未加以证明。本文给出证明&…

概率统计14——几何分布

我家小朋友年方1岁半&#xff0c;家里每天上午都要出去遛小孩。现在小朋友有两项爱好&#xff0c;在家翻垃圾桶&#xff0c;出门捡烟头。 翻垃圾桶可以有效地限制&#xff0c;捡烟头可是防不胜防。 也许烟头能散发出特殊的能量波动&#xff0c;小区的绿化带和草坪上的大部分烟…

超几何分布定义

设有N件产品&#xff0c;其中有M&#xff08;M≤N&#xff09;件是不合格品&#xff0e;若从中不放回地抽取n&#xff08;n≤N&#xff09;件&#xff0c;设其中含有的不合格品的件数为X&#xff0c;则X的分布律为 称X服从参数为N、M和n的超几何分布&#xff0c;记为X~H&#x…

几何分布和二项分布有什么区别?

● 每周一言 越长大越渺小。 导语 各种常见的分布中&#xff0c;二项分布和几何分布经常同时出现&#xff0c;在前面讲泊松分布的时候也简单提到了二项分布。那么&#xff0c;几何分布是什么分布&#xff1f;和二项分布有什么区别&#xff1f; 几何分布 讲泊松分布的时候提…

几何分布定义

在伯努利试验中&#xff0c;记每次试验中A事件发生的概率P&#xff08;A&#xff09;p&#xff08;0<p<1&#xff09;&#xff0c;设随机变量X表示A事件首次出现时已经试验的次数&#xff0c;则X的取值为1&#xff0c;2&#xff0c;…&#xff0c;n&#xff0c;…&#x…