当前位置:首页 > VUE

vue实现steps步骤条

2026-02-22 13:56:22VUE

Vue 实现 Steps 步骤条

使用 Element UI 的 Steps 组件

安装 Element UI 库:

npm install element-ui

在 Vue 文件中引入 Steps 组件:

vue实现steps步骤条

<template>
  <div>
    <el-steps :active="active" finish-status="success">
      <el-step title="步骤 1"></el-step>
      <el-step title="步骤 2"></el-step>
      <el-step title="步骤 3"></el-step>
    </el-steps>
    <el-button @click="next">下一步</el-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      active: 0
    }
  },
  methods: {
    next() {
      if (this.active++ > 2) this.active = 0
    }
  }
}
</script>

使用 Ant Design Vue 的 Steps 组件

安装 Ant Design Vue 库:

npm install ant-design-vue

在 Vue 文件中引入 Steps 组件:

vue实现steps步骤条

<template>
  <div>
    <a-steps :current="current">
      <a-step title="步骤 1" />
      <a-step title="步骤 2" />
      <a-step title="步骤 3" />
    </a-steps>
    <a-button type="primary" @click="next">下一步</a-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      current: 0
    }
  },
  methods: {
    next() {
      if (this.current++ > 2) this.current = 0
    }
  }
}
</script>

自定义 Steps 组件

创建一个自定义 Steps 组件:

<template>
  <div class="steps">
    <div
      v-for="(step, index) in steps"
      :key="index"
      class="step"
      :class="{ active: currentStep === index, completed: currentStep > index }"
    >
      <div class="step-circle">{{ index + 1 }}</div>
      <div class="step-title">{{ step.title }}</div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    steps: {
      type: Array,
      required: true
    },
    currentStep: {
      type: Number,
      default: 0
    }
  }
}
</script>

<style>
.steps {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
}
.step {
  flex: 1;
  text-align: center;
  position: relative;
}
.step-circle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #ccc;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 10px;
}
.step.active .step-circle {
  background: #409eff;
}
.step.completed .step-circle {
  background: #67c23a;
}
.step-title {
  color: #999;
}
.step.active .step-title {
  color: #409eff;
}
.step.completed .step-title {
  color: #67c23a;
}
</style>

在父组件中使用自定义 Steps 组件:

<template>
  <div>
    <custom-steps :steps="steps" :current-step="currentStep" />
    <button @click="nextStep">下一步</button>
  </div>
</template>

<script>
import CustomSteps from './CustomSteps.vue'

export default {
  components: {
    CustomSteps
  },
  data() {
    return {
      steps: [
        { title: '第一步' },
        { title: '第二步' },
        { title: '第三步' }
      ],
      currentStep: 0
    }
  },
  methods: {
    nextStep() {
      if (this.currentStep < this.steps.length - 1) {
        this.currentStep++
      }
    }
  }
}
</script>

标签: 步骤vue
分享给朋友:

相关文章

实现vue框架

实现vue框架

Vue框架的基本实现 Vue是一个渐进式JavaScript框架,用于构建用户界面。以下是实现Vue框架的基本步骤: 安装Vue 通过CDN引入Vue是最简单的方式: <script src…

proxy实现vue

proxy实现vue

使用 Proxy 实现 Vue 响应式系统 Vue 3 的响应式系统基于 JavaScript 的 Proxy API,通过代理对象实现对属性的拦截和依赖追踪。以下是实现的核心逻辑: 创建响应式对象…

vue 实现hover

vue 实现hover

Vue 实现 Hover 效果的方法 在 Vue 中实现 hover 效果可以通过多种方式完成,以下是几种常见的方法: 使用 CSS 伪类 :hover 最简单的方式是直接使用 CSS 的 :hov…

vue日历实现

vue日历实现

实现基础日历布局 使用Vue的模板语法构建日历的基本HTML结构。一个典型的日历包含星期标题和日期格子,可以通过v-for循环生成。月份切换功能通过计算属性动态更新日期数组。 <templat…

vue实现单词反转

vue实现单词反转

实现单词反转的方法 在Vue中实现单词反转可以通过多种方式完成,以下是几种常见的方法: 方法一:使用计算属性 在Vue组件中定义一个计算属性,利用JavaScript的字符串和数组方法实现反转。…

vue实现条件判断

vue实现条件判断

Vue 中的条件判断实现方式 Vue 提供了多种方式实现条件判断,以下是常用的几种方法: v-if 指令 v-if 指令根据表达式的真假值动态添加或移除 DOM 元素。当条件为假时,元素会被完全移除…