当前位置:首页 > VUE

vue实现流程高亮

2026-02-20 12:27:04VUE

Vue 实现流程高亮的方法

使用动态类绑定

通过 Vue 的 v-bind:class 或简写 :class 动态绑定类名,根据当前步骤激活高亮样式。定义一个数据属性(如 currentStep)记录当前步骤,结合 CSS 实现高亮效果。

<template>
  <div>
    <div 
      v-for="(step, index) in steps" 
      :key="index" 
      :class="{ 'active-step': index === currentStep }"
    >
      {{ step }}
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      steps: ['步骤1', '步骤2', '步骤3'],
      currentStep: 0
    };
  }
};
</script>

<style>
.active-step {
  color: #42b983;
  font-weight: bold;
}
</style>

结合 Vue Router 实现路由高亮

若流程与路由关联,可通过 Vue Router 的 router-linkactive-class 属性实现导航高亮。

<template>
  <div>
    <router-link 
      v-for="(route, index) in routes" 
      :key="index" 
      :to="route.path"
      active-class="active-route"
    >
      {{ route.name }}
    </router-link>
  </div>
</template>

<script>
export default {
  data() {
    return {
      routes: [
        { path: '/step1', name: '步骤1' },
        { path: '/step2', name: '步骤2' }
      ]
    };
  }
};
</script>

<style>
.active-route {
  border-bottom: 2px solid #42b983;
}
</style>

使用第三方库

借助 vue-step-wizard 等库快速实现流程高亮。安装后直接使用组件,内置高亮逻辑。

npm install vue-step-wizard
<template>
  <step-wizard>
    <step>步骤1</step>
    <step>步骤2</step>
  </step-wizard>
</template>

<script>
import { StepWizard, Step } from 'vue-step-wizard';
export default {
  components: { StepWizard, Step }
};
</script>

自定义组件封装

封装可复用的流程组件,通过插槽和 props 控制高亮逻辑。

<template>
  <div class="process-container">
    <slot :current="currentStep"></slot>
  </div>
</template>

<script>
export default {
  props: {
    currentStep: { type: Number, default: 0 }
  }
};
</script>

调用时通过作用域插槽获取当前步骤状态:

<process-container :current-step="1">
  <template v-slot="{ current }">
    <div :class="{ 'highlight': current === 0 }">步骤1</div>
    <div :class="{ 'highlight': current === 1 }">步骤2</div>
  </template>
</process-container>

动画过渡效果

通过 Vue 的 <transition> 组件为高亮切换添加动画,增强用户体验。

vue实现流程高亮

<transition name="fade">
  <div v-if="isActive" class="highlight-step">当前步骤</div>
</transition>

<style>
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter, .fade-leave-to {
  opacity: 0;
}
.highlight-step {
  background-color: #e3f2fd;
}
</style>

标签: 流程vue
分享给朋友:

相关文章

vue实现适老化样式

vue实现适老化样式

Vue 实现适老化样式的关键方法 全局字体与字号调整 通过 CSS 变量或主题配置统一放大基础字号,建议正文不小于 18px,标题更大。在 App.vue 中设置全局样式: :root { --…

vue公共列表的实现

vue公共列表的实现

实现 Vue 公共列表组件 公共列表组件通常用于展示重复结构的数据,例如商品列表、用户列表等。以下是一个典型的实现方式: 基础实现 创建可复用的列表组件 List.vue: <templat…

vue实现钟表

vue实现钟表

使用 Vue 实现动态钟表 以下是一个基于 Vue 3 的动态钟表实现方案,包含时分秒指针和数字时间显示。 模板部分 <template> <div class="clock-…

vue实现mvc

vue实现mvc

Vue 实现 MVC 模式 Vue 本身是一个 MVVM(Model-View-ViewModel)框架,但可以通过结构调整实现 MVC(Model-View-Controller)模式。以下是具体实…

vue实现旋转

vue实现旋转

Vue 实现旋转效果的方法 在 Vue 中实现旋转效果可以通过多种方式完成,以下是几种常见的方法: 使用 CSS 动画 通过 Vue 的 :class 或 :style 绑定 CSS 动画实现旋转效…

vue 实现blog

vue 实现blog

Vue 实现博客的基本步骤 使用 Vue 实现博客可以分为前端和后端两部分,前端使用 Vue.js 框架,后端可以选择 Node.js、Python 或其他服务端语言。以下是一个基于 Vue 的博客实…