vue编写步骤条组件

 

 

<template>
  <div class="step-wrapper">
    <!-- 步骤条盒子 -->
    <div class="step-title-wrapper" v-for="(item,index) in stepList">
      <span class="el-icon-circle-check" v-if="item.success"></span>
      <span :class="['step-number', {'activeNumber':activeIndex === index}]" v-else>{{item.stepIndex}}</span>
      <span :class="['step-title', {'activeTitle':activeIndex === index}, {'successTitle': item.success}]">{{ item.title }}</span>
      <span :class="['line-step', {'success-line': item.success}]" v-if="stepList.length - 1 > index"></span>
    </div>
<!--    <button @click="lastStep">上一个</button>-->
<!--    <button @click="nextStep">下一个</button>-->

  </div>
</template>

<script>
export default {
  name: 'index',
  props: {
    stepList: { //步骤条步数
      type: Array,
      default: []
    }
    // 示例
    // {
    //       stepIndex: 1,
    //       title: "基本信息",
    //       success: false
    //     },
  },
  data() {
    return {
      //当前位置
      activeIndex: 0,

    };
  },
  methods: {
    //点击下一步
    nextStep() {
        this.activeIndex += 1;
        if(this.stepList.length < this.activeIndex ) {
          this.activeIndex = 0
          this.stepList.forEach((item)=> {item.success = false})
        }
        if (this.activeIndex > 0) {
          this.stepList[this.activeIndex-1].success = true
        }
    },
    //点击上一步
    lastStep() {
      if (this.activeIndex > 0) {
        this.activeIndex -= 1;
        this.stepList[this.activeIndex].success = false
      }
    }
  }

}
</script>

<style scoped lang="less">
.step-wrapper{
  display: flex;
  margin-bottom: 40px;
}
.step-title-wrapper{
   display: flex;
  align-items: center;

  .step-number{
    box-sizing: border-box;
    display: inline-block;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid #00000047;
    color: #00000047;
    font-size: 16px;
    line-height: 24px;
    text-align: center;
  }

  .activeNumber{
    border: none;
    background: #18A0FB;
    color: #fff;
  }
  .el-icon-circle-check{
     color: #18A0FB;
     font-size: 24px;
  }
  .step-title{
    margin-left: 12px;
    font-size: 14px;
    color: #00000047;
  }
  .activeTitle{
     color: #000000D8;
  }
  .successTitle{
     color: #18A0FB;
  }
  .line-step{
    width: 180px;
    height: 2px;
    display: inline-block;
    background: #E5E5E5;
    margin-left: 18px;
    margin-right: 10px;
  }
  .success-line{
     background: #18A0FB;
  }
}
</style>

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值