当前位置:首页 > VUE

vue实现steps步骤条

2026-02-22 13:56:22VUE

Vue 实现 Steps 步骤条

使用 Element UI 的 Steps 组件

安装 Element UI 库:

npm install element-ui

在 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 组件:

<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实现steps步骤条

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

相关文章

vue实现放大效果

vue实现放大效果

使用 CSS transform 实现放大效果 在 Vue 中实现放大效果可以通过 CSS 的 transform: scale() 属性。这种方法简单高效,适合大多数交互场景。 定义一个 CSS…

vue   实现单选

vue 实现单选

Vue 实现单选功能 在 Vue 中实现单选功能可以通过多种方式,以下是几种常见的方法: 使用原生 <input type="radio"> 绑定 v-model 通过 v-model…

vue实现跑车

vue实现跑车

Vue 实现跑车动画效果 使用 Vue 结合 CSS 动画可以实现跑车在屏幕上移动的效果。以下是一个完整的实现方案: 创建 Vue 组件结构 <template> <div c…

vue实现删除

vue实现删除

Vue 实现删除功能的方法 在 Vue 中实现删除功能通常涉及以下几个步骤: 数据绑定与列表渲染 使用 v-for 指令渲染列表数据,并为每个项绑定唯一标识符(如 id)。例如: <ul…

vue实现erp

vue实现erp

Vue实现ERP系统的关键步骤 技术选型与架构设计 采用Vue 3 + TypeScript构建前端,搭配Pinia状态管理,Element Plus或Ant Design Vue作为UI框架。后端可…

vue实现换行

vue实现换行

Vue 中实现换行的几种方法 在 Vue 中实现换行可以通过多种方式,具体取决于使用场景和需求。以下是常见的几种方法: 使用 HTML 的 <br> 标签 在模板中直接使用 <b…