uniapp+vue+css手写步骤条组件
    		       		warning:
    		            这篇文章距离上次修改已过450天,其中的内容可能已经有所变动。
    		        
        		                
                以下是一个简单的uniapp+vue+css手写步骤条组件的示例代码:
<template>
  <view class="step-container">
    <view
      class="step"
      v-for="(item, index) in steps"
      :key="index"
      :class="{'active': index === activeStep}"
    >
      <view class="step-number">
        <text v-if="index < activeStep || (index === activeStep && !isLastStep)">✓</text>
        <text v-else>{{ index + 1 }}</text>
      </view>
      <view class="step-text">{{ item }}</view>
    </view>
  </view>
</template>
 
<script>
export default {
  props: {
    steps: {
      type: Array,
      default: () => ['步骤1', '步骤2', '步骤3']
    },
    activeStep: {
      type: Number,
      default: 0
    }
  },
  computed: {
    isLastStep() {
      return this.activeStep === this.steps.length - 1;
    }
  }
};
</script>
 
<style scoped>
.step-container {
  display: flex;
  align-items: center;
}
 
.step {
  display: flex;
  align-items: center;
  font-size: 14px;
  position: relative;
  padding: 10px 20px;
  color: #757575;
}
 
.step-number {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #e0e0e0;
  margin-right: 10px;
}
 
.step-text {
  white-space: nowrap;
}
 
.active {
  color: #005f69;
}
 
.active .step-number {
  background-color: #005f69;
  color: #fff;
}
 
.active .step-number text {
  font-size: 20px;
}
</style>这个组件接收两个props:steps 和 activeStep。steps 是一个包含步骤描述的数组,activeStep 是当前激活步骤的索引。组件使用计算属性 isLastStep 来判断是否是最后一个步骤,从而显示不同的图标。CSS样式定义了步骤条的外观和感觉。
评论已关闭