vue 自定義步驟條組件(css)


話不多說直接上組件代碼。。

<template>
  <div>
    <ul class="steps">
      <li
        v-for="(item,index) in SetData"
        :key="item+index"
        :class="{'active':Steps===index}"
      >{{item+Steps}}</li>
    </ul>
  </div>
</template>
<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
import axios from "axios";
@Component
export default class Steps extends Vue {
  @Prop({default:0}) private Steps!: number;
  @Prop() private SetData!: string[];
}
</script>

<style>
.steps {
  position: relative;
  margin-bottom: 30px;
  counter-reset: step; /*創建步驟數字計數器*/
}
/*步驟描述*/
.steps li {
  list-style-type: none;
  font-size: 12px;
  text-align: center;
  width: 15%;
  position: relative;
  float: left;
}

/*步驟數字*/
.steps li:before {
  display: block;
  content: counter(step); /*設定計數器內容*/
  counter-increment: step; /*計數器值遞增*/
  width: 32px;
  height: 32px;
  background-color: #019875;
  line-height: 32px;
  border-radius: 32px;
  font-size: 16px;
  color: #fff;
  text-align: center;
  font-weight: 700;
  margin: 0 auto 8px auto;
}

/*連接線*/
.steps li ~ li:after {
  content: "";
  width: 100%;
  height: 2px;
  background-color: #019875;
  position: absolute;
  left: -50%;
  top: 15px;
  z-index: -1; /*放置在數字后面*/
}

/*將當前/完成步驟之前的數字及連接線變綠*/
.steps li.active:before,
.steps li.active:after {
  background-color: #019875;
}

/*將當前/完成步驟之后的數字及連接線變灰*/
.steps li.active ~ li:before,
.steps li.active ~ li:after {
  background-color: #777;
}
</style>

調用組件。。。

<template>
  <div>
    {{num1}}
    <el-button type="warning" @click="getNumber">get a random number</el-button>
    <Steps :Steps="registSpets" :SetData="SetData" />
    <el-button type="primary" @click="registSpets++">+++</el-button>
    {{registSpets}}
    <el-button type="danger" @click="registSpets--">---</el-button>
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
import Steps from "../components/Steps.vue";
@Component({
  components: {
    Steps
  }
})
export default class Input extends Vue {
  num1: number = 0;
  registSpets = 1;
  SetData = ["用戶信息", "魔童哪吒", "齊天大聖", "赤腳大仙", "我愛中國"];
  getNumber() {
    this.num1 = Math.ceil(Math.random() * 10); // Matg.ceil向上取整
  }
}
</script>

效果如下:

參考原文:https://blog.csdn.net/xqq580231/article/details/78086173


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM