当前位置:首页 > 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中实现导航切换内容,可以通过以下方式实现: 使用动态组件 动态组件通过<component :is="currentComponent">实现内容切…

vue手写签名如何实现

vue手写签名如何实现

实现手写签名的基本思路 在Vue中实现手写签名功能,通常需要借助HTML5的Canvas API来捕获用户的绘制操作。核心流程包括初始化画布、监听触摸/鼠标事件、记录轨迹以及生成签名图片。…

vue实现新闻

vue实现新闻

Vue 实现新闻功能 使用 Vue 实现新闻功能通常涉及新闻列表展示、新闻详情页、分类筛选等模块。以下是实现的基本思路和代码示例。 新闻列表展示 通过 Vue 组件展示新闻列表,通常使用 v-for…

vue实现长按

vue实现长按

Vue 实现长按功能的方法 在 Vue 中实现长按功能可以通过原生事件监听或自定义指令完成。以下是几种常见实现方式: 使用原生事件监听 通过 @mousedown 和 @mouseup 或 @tou…

vue实现前端

vue实现前端

Vue 实现前端的核心方法与步骤 安装 Vue 项目 使用 Vue CLI 或 Vite 创建项目。Vue CLI 是传统构建工具,Vite 是新一代轻量级工具。 npm init vue@la…

vue nexttrick实现

vue nexttrick实现

Vue 中 nextTick 的实现原理 nextTick 是 Vue 提供的一个异步方法,用于在下次 DOM 更新循环结束之后执行延迟回调。它利用了 JavaScript 的事件循环机制,确保回调在…