VUE自定步骤条

我们在开发的工程当中呢总会遇到组件库无法满足需求的问题,所以以下就是我在开放过程当中所遇到的问题,组件库的步骤条比较丑,为了UI给出的实际图,自己来开发了一个,废话不多说上代码

html代码部分

<template>
  <div class="steps">
    <template v-for="(item, index) in props.items" :key="item.key">
      <div :style="{ width: otherWidth, position: 'relative', left: -(size * index) + 'px' }" v-if="!index" class="item">
        <div class="item-flex start" :class="props.current >= index ? 'current' : ''">
          <span class="border" :class="props.current >= index ? 'Select' : ''">{{ index + 1 }}</span>
          <span class="font">{{ item.title }}</span>
        </div>
      </div>
      <div :style="{ width: otherWidth, position: 'absolute', left: lastLeft, top: 0 }" v-else-if="index === props.items.length - 1" class="item">
        <div class="item-flex end" :class="props.current >= index ? 'current' : ''">
          <span class="border" :class="props.current >= index ? 'Select' : ''">{{ index + 1 }}</span>
          <span class="font">{{ item.title }}</span>
        </div>
      </div>
      <div :style="{ width: otherWidth, position: 'relative', left: -(size * index) + 'px' }" v-else class="item">
        <div class="item-flex center" :class="props.current >= index ? 'current' : ''">
          <span class="border" :class="props.current >= index ? 'Select' : ''">{{ index + 1 }}</span>
          <span class="font">{{ item.title }}</span>
        </div>
      </div>
    </template>
  </div>
</template>

JavaScript代码部分

因为是按照组件可的步骤条来开发的,所以我们也会需要在调用组件的时候来传递参数分别是items和current,items是他的步骤名称,current则是他的步骤索引,

<script setup lang="ts">
  import { defineProps, computed } from 'vue';

  const props = defineProps({
    items: [] as any,
    current: Number,
  });

  // 每个平移 15px
  const size = 15;

  const otherWidth = computed(() => {
    const length = props.items.length;
    const total = size * (length - 1);
    return `calc(${Number((1 / length).toFixed(4)) * 100}% + ${total / length}px)`;
  });
  const lastLeft = computed(() => {
    const length = props.items.length;
    const total = size * (length - 1);
    return `calc(${Number((1 - 1 / length).toFixed(4)) * 100}% - ${total / length}px)`;
  });
</script>

css代码部分

最后呢则是此组件的样式部分

<style scoped lang="less">
  .steps {
    //display: flex;
    width: 100%;
    height: 40px;
    align-items: center;
    position: relative;
    overflow: hidden;
    .item {
      display: inline-block;
      width: v-bind(otherWidth);

      //font-weight: 600;

      //align-content: center;

      .item-flex {
        height: 40px;
        text-align: left;
        line-height: 40px;
        background-color: #fff;
        color: #4e5969;
        font-size: 14px;
        align-items: center;
        justify-content: flex-start;
        padding-left: 25px;
        display: flex;
        .font {
          letter-spacing: 2px;
          margin-left: 8px;
          min-width: 70px;
          white-space: nowrap;
          text-overflow: ellipsis;
        }

        .border {
          display: block;
          min-width: 20px;
          min-height: 20px;
          text-align: center;
          line-height: 16px;
          border-radius: 100%;
          border: 2px solid #4e5969;
          color: #4e5969;
        }

        .Select {
          display: block;
          width: 20px;
          height: 20px;
          text-align: center;
          line-height: 16px;
          border-radius: 100%;
          border: 2px solid #fff;
          background-color: #fff;
          color: #1677ff;
        }

        &.start {
          clip-path: polygon(0 0, 0 100%, calc(100% - 20px) 100%, 100% 50%, calc(100% - 20px) 0);
        }

        &.center {
          clip-path: polygon(0 0, 20px 50%, 0 100%, calc(100% - 20px) 100%, 100% 50%, calc(100% - 20px) 0);
        }

        &.end {
          clip-path: polygon(0 0, 20px 50%, 0 100%, 100% 100%, 100% 50%, 100% 0);
        }

        &.current {
          background-color: #1677ff;
          color: #ffffff;
        }

        &.blue {
          background-color: #e4f2fe;
          color: #1677ff;
        }
      }
    }
  }
</style>

此代码可以直接复制来使用,原创不易,如需要代码的话请点赞收藏哦,

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现vue-i18n自定义数据的切换,可以按照以下步骤进行操作: 1. 首先,在Vue项目中安装vue-i18n插件,并在main.js中导入和使用该插件。可以使用npm或yarn命令安装vue-i18n,然后在main.js中导入和使用插件。例如:import VueI18n from 'vue-i18n',Vue.use(VueI18n)。 2. 创建一个i18n实例,并配置语言资源文件。可以在项目的src目录下创建一个lang文件夹,用于存放不同语言的资源文件。在该文件夹中,创建一个名为en.js的文件,用于存放英文资源,创建一个名为zh.js的文件,用于存放中文资源。每个资源文件都是一个JavaScript模块,导出一个对象,对象的属性名为消息的key,属性值为消息的值。例如: en.js: export default { message: { hello: 'Hello', goodbye: 'Goodbye' } } zh.js: export default { message: { hello: '你好', goodbye: '再见' } } 3. 在组件中使用vue-i18n。在组件中,可以通过在模板中使用特定的标记来显示不同语言的消息。例如,在模板中使用{{$t('message.hello')}}来显示hello消息。在组件的script部分,可以通过this.$i18n.locale来获取当前的语言,并通过this.$i18n.setLocale方法来切换语言。例如,在methods中使用this.$i18n.setLocale('en')来切换到英文。 4. 在页面或组件中添加语言切换的功能。可以在页面或组件中添加一个语言切换的按钮或下拉框,通过绑定点击事件或选择事件来调用切换语言的方法。 综上所述,以上是使用vue-i18n实现自定义数据切换的步骤。您可以根据具体需求进行配置和调整。 <span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [vuevue-i18n结合实现后台数据的多语言切换方法](https://download.csdn.net/download/weixin_38710557/12762700)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [使用 vue-i18n 切换中英文效果](https://download.csdn.net/download/weixin_38635684/12759285)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [ruoyi-vue-pro yudao 项目报表设计器 积木报表模块启用及相关SQL脚本](https://download.csdn.net/download/zengwenbo225566/88234865)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值