打造你的专属Vue组件:超实用“鱼骨步骤条“组件实战开发

🎉 在众多UI设计领域中,"鱼骨步骤条"凭借其✨清晰直观✨地展现流程进度,赢得了设计者们的大量青睐!本篇博客将带你飞越Vue框架的广袤天地,从零到一,亲手锻造一款既美观又功能强大的定制化"鱼骨步骤条"组件。我们不仅会深潜入组件的巧妙构思水域,还会逐一探索其实现的每一个细节,确保你在项目中游刃有余地重复利用这一神器🐟。

🎯 组件UI效果展示

👇 查看下方,一睹为快我们即将打造的"鱼骨步骤条"风采吧!它将以灵动的身姿,清晰标示出每一步骤的状态,为你的用户导航!	

在这里插入图片描述

🔧 配置参数概览

接下来,一览那些让你自由定制的配置选项。只需简单的设置,即可让"鱼骨步骤条"完美融入你的界面设计中!

在这里插入图片描述

👷‍♂️ 基础使用教程

想立即上手?跟上这简单的代码步伐,轻松集成到你的Vue项目中吧!记得调整表情和标签,让你的代码也生动起来哦!	
<template>
  <HIndicator :indicator-data="indicatorData" :is-show-remark="true">
   <!-- 自定义备注槽位 -->
    <template #remarks="{ scope }">
      {{ scope.row.remark }}
    </template>
  </Indicator>1
</template>
<script setup>
defineOptions({
  name: 'h-indicator'
})
// 定义数据模型
const indicatorData = [
    {
        label: '第一步',
        background: '#3188E6',
        isLongShowRemark: true,
        remark: '长显备注一'
    },
    {
        label: '第二步',
        background: '#3188E6',
        remark: '长显备注二',
    },
    {
        label: '第三步',
        background: '#3188E6',
        remark: '长显备注三',
        active: true
    },
    {
        label: '第四步',
        background: '#3188E6',
        remark: '备注四'
    },
    {
        label: '第五步',
        background: '#3188E6',
        remark: '备注五'
    },
    {
        label: '第六步',
        background: 'red',
        textColor: '#343434',
        remark: '备注六'
    },
    {
        label: '第七步',
        borderColor: '#ccc'
    }
]
</script>

<style lang="scss" scoped></style>

🛠 组件核心实现揭秘

<template>
  <div class="indicator">
    <IndicatorItem
      class="indicator-item"
      v-for="(item, index) in indicatorData"
      :item-bg="item.background"
      :key="index"
      :type="typeCmpFun(index)"
      :style="styleConfig(item, index)"
      :borderColor="item.borderColor"
      :textColor="item.textColor"
    >
      <div
        class="texts"
        :style="{
          color: item.textColor
            ? item.textColor
            : item.background
            ? item.textColor || '#fff'
            : '#343434',
        }"
      >
        {{ item.label }}
      </div>
      <div
        class="remarks"
        :class="{ remarksLong: item.isLongShowRemark, active: item.active }"
        v-if="item.remark && isShowRemark"
      >
        <slot name="remarks" :scope="{ row: item }" />
      </div>
    </IndicatorItem>
  </div>
</template>

<script setup>
import IndicatorItem from './indicatorItem.vue'

defineOptions({
  name: 'HIndicator'
})

const props = defineProps({
  // 数据
  indicatorData: {
    type: Array as unknown as any[],
    default: () => [],
  },
  // 是否显示下方备注
  isShowRemark: {
    type: Boolean,
    default: false,
  }
})
const typeCmpFun= computed(() => {
  return function (index) {
    if (index === 0) {
      return 'start'
    }
    if (index === props.indicatorData.length - 1) {
      return 'end'
    }
    return 'center'
  }
})

const styleConfig= computed(() => {
  return function (item, index) {
    return {
      background: item.background,
      zIndex: props.indicatorData.length - index,
      left: index !== 0 ? `${index * 10}px` : 0,
    }
  }
})
</script>

<style lang="scss" scoped>
.indicator {
  display: flex;
  &-item {
    font-size: 14px;
    .texts {
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    &:not(:first-child) {
      .texts {
        padding-left: 20px;
        position: absolute;
        z-index: 10;
      }
    }
    .remarks {
      display: flex;
      width: calc(100% + 2px);
      height: auto;
      padding: 0 6px;
      opacity: 0;
      visibility: hidden;
      border: 1px solid rgba(26, 78, 199, 0.2);
      border-top: 0;
      background: #fff;
      position: absolute;
      top: 39px;
      left: -1px;
      line-height: initial;
      transition: all 0.3s;
    }
    &:hover {
      .remarks {
        height: auto;
        padding: 12px 6px 10px 6px;
        opacity: 1;
        visibility: inherit;
      }
    }
    .remarksLong {
      height: auto;
      padding: 12px 6px 10px 6px;
      opacity: 1;
      visibility: inherit;
    }
    .active {
      border-color: #32a0ff;
    }
  }
}
</style>

🧩 IndicatorItem 组件奥秘

<template>
  <div
    class="indicatoritem"
    :class="{
      'indicatoritem-start': type === 'start',
      'indicatoritem-end': type === 'end',
      'indicatoritem-center': !['start', 'end'].includes(type),
    }"
  >
    <slot></slot>
  </div>
</template>

<script setup>
defineOptions({
  name: 'IndicatorItem'
})
const prop = defineProps({
  // 箭头类型 start center end
  type: {
    type: String,
    default: 'center',
  },
  // 整体的背景颜色
  background: {
    type: String,
    default: '#fff',
  },
  // 背景颜色
  itemBg: {
    type: String,
    default: '',
  },
  // 边框颜色
  borderColor: {
    type: String,
    default: 'transparent',
  },
  // 文字颜色
  textColor: {
    type: String,
    default: '#fff',
  },
})
</script>
<style lang="scss" scoped>
.indicatoritem {
  min-width: 13%;
  height: 40px;
  position: relative;
  background: v-bind(itemBg);
  text-align: center;
  line-height: 40px;
  border: 1px solid v-bind(borderColor);
  border-right: none;
}
.indicatoritem:after {
  content: '';
  position: absolute;
  top: 5px;
  left: -15px;
  right: auto;
  width: 28px;
  height: 28px;
  border: 1px solid v-bind(borderColor);
  border-left: 1px solid transparent;
  border-bottom: 1px solid transparent;
  transform: rotate(45deg);
  background: v-bind(background);
}
.indicatoritem:before {
  content: '';
  position: absolute;
  top: 5px;
  right: -14px;
  left: auto;
  width: 28px;
  height: 28px;
  border: 1px solid v-bind(borderColor);
  border-left: 1px solid transparent;
  border-bottom: 1px solid transparent;
  transform: rotate(45deg);
  background: v-bind(itemBg);
}
.indicatoritem-start::after {
  content: none !important;
}
.indicatoritem-end::before {
  content: none !important;
}
.indicatoritem-end {
  border-right: 1px solid v-bind(borderColor);
}
</style>

现在,你已经掌握了构建个性化"鱼骨步骤条"组件的全部秘诀!无论是为提升用户体验还是美化界面布局,这个组件都将是你不可或缺的得力助手。🚀 别忘了动手实践,让你的应用界面焕发出新的光彩!

  • 14
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue3是一种流行的JavaScript框架,用于构建用户界面。Vue Router是Vue.js的官方路由器,用于实现单页面应用程序的导航功能。Vite是一个快速的Web开发构建工具,具有即时重载和快速的开发体验。Pinia是一个简单、快速、类型安全的状态管理库。 使用Vue3、Vue Router、Vite和Pinia进行组件开发实战入门非常简单。 首先,我们需要安装Vue3和相关的库。可以使用npm或yarn来安装它们。在项目的根目录中运行以下命令: ``` npm install vue@next vue-router@next @pinia/vue@next vite --save ``` 安装完成后,我们可以开始创建一个Vue应用程序。在项目的根目录中创建一个`src`文件夹,并在其中创建一个`main.js`文件。在`main.js`文件中,我们需要导入VueVue Router和Pinia,并创建一个Vue实例。代码示例如下: ```javascript // main.js import { createApp } from 'vue'; import { createRouter, createWebHistory } from 'vue-router'; import { createPinia } from 'pinia'; // 导入组件 import App from './App.vue'; // 创建路由 const router = createRouter({ history: createWebHistory(), routes: [ // 定义路由 { path: '/', component: Home } ] }); // 创建 Pinia 实例 const pinia = createPinia(); // 创建 Vue 实例 const app = createApp(App); // 使用路由和 Pinia app.use(router); app.use(pinia); // 挂载应用 app.mount('#app'); ``` 现在,我们可以创建一个简单的Vue组件。在`src`文件夹中创建一个名为`App.vue`的文件,并在其中定义一个组件。在组件中,我们可以使用Pinia来管理组件的状态,使用Vue Router来处理导航。 ```html <!-- App.vue --> <template> <div> <router-view></router-view> <button @click="increment">增加计数器</button> <p>{{ count }}</p> </div> </template> <script> import { defineComponent } from 'vue'; import { useCounter } from '../store'; export default defineComponent({ setup() { const counter = useCounter(); const increment = () => { counter.increment(); }; return { count: counter.count, increment }; } }); </script> ``` 在上述示例中,我们创建了一个Counter组件,其中包含一个用于增加计数器的按钮和一个显示计数器值的段落。我们使用Pinia的`useCounter`钩子来访问和修改计数器的状态。 最后,在项目的根目录中运行以下命令启动应用程序: ``` npm run dev ``` 以上就是使用Vue3、Vue Router、Vite和Pinia进行组件开发实战入门的一个简单示例。通过深入学习这些工具和框架,您将能够构建更复杂、功能丰富的应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值