vue3 多行步骤条

vue3 多行步骤条

效果图

<template>
  <div
    class="list"
    ref="list"
  >
    <div
      v-for="item in arr"
      :key="item.index"
      class="itemBox"
      :style="{float:item.float}"
    >
      <img
        src="/img/svg/icon-left.svg"
        v-if="item.imgDirection == 'left'"
        style="width:54px"
      >
      <div
        class="content"
        ref="content"
      >
        {{item.index}}
      </div>
      <img
        src="/img/svg/icon-right.svg"
        v-if="item.imgDirection == 'right'"
        style="width:54px"
      >
      <img
        class="imgBottom"
        src="/img/svg/icon-bottom.svg"
        v-if="item.imgDirection == 'bottom'"
      >
    </div>
  </div>
</template>
<script setup>
import { ref, reactive, onMounted, getCurrentInstance } from "vue";
const list = ref(null);
const content = ref([]);

let arr = ref([]);
for (let i = 0; i < 40; i++) {
  arr.value.push({
    index: i,
    imgDirection: null,
    float: null,
  });
}

// 计算
function test() {
  list.value.style.width = "100%";
  let listWidth = list.value.offsetWidth + 6;
  let contentWidth = content.value[0].offsetWidth + 6;
  let imgWidth = 54;

  let eachRowNum = Math.floor(
    (listWidth - contentWidth) / (contentWidth + imgWidth) + 1
  );

  let listDesireWidth =
    contentWidth + (contentWidth + imgWidth) * (eachRowNum - 1);
  list.value.style.width = listDesireWidth + "px";

  for (let i = 0; i < arr.value.length; i++) {
    let item = arr.value[i];
    let row = Math.floor(i / eachRowNum);
    let column = (i % eachRowNum) + 1;

    if (row % 2 == 0) {
      // 奇数行
      item.float = "left";
      if (column != eachRowNum) {
        item.imgDirection = "right";
      } else {
        item.imgDirection = "bottom";
      }
    } else {
      // 偶数行
      item.float = "right";
      if (column != eachRowNum) {
        item.imgDirection = "left";
      } else {
        item.imgDirection = "bottom";
      }
    }
    if (i == arr.value.length - 1) {
      item.imgDirection = "";
    }
  }
}

onMounted(() => {
  test();
  window.onresize = () => {
    test();
  };
});
</script>
<style scope lang="scss">
.list {
  overflow: hidden;
  .itemBox {
    position: relative;
    margin-bottom: 40px;
    .content {
      width: 100px;
      height: 30px;
      box-sizing: border-box;
      background-color: #f99;
      border-radius: 5px;
      margin: 3px;
      display: inline-block;
    }
    .imgBottom {
      position: absolute;
      left: 50%;
      bottom: 0;
      transform: translate(-50%, 100%);
    }
  }
}
</style>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue2的步骤条(Steps)是一种常用的UI组件,用于展示多个步骤的进度和状态。下面是使用Vue2步骤条的一般步骤: 1. 首先,确保你已经安装了Vue.js和Vue2步骤条的依赖包。可以通过npm或者yarn进安装。 2. 在你的Vue组件中引入Vue2步骤条的库文件。可以使用import语句将其引入到你的组件中。 3. 在Vue组件的template中,使用`<steps>`标签来创建步骤条组件。可以通过设置不同的属性来定义步骤条的样式和为。 4. 在`<steps>`标签内部,使用`<step>`标签来定义每个步骤。可以设置不同的属性来定义每个步骤的标题、描述和状态。 5. 在Vue组件的script中,可以通过data属性来定义步骤条的数据。例如,可以使用一个数组来存储每个步骤的信息。 6. 可以通过methods属性来定义一些方法,用于处理步骤条的交互逻辑。例如,可以定义一个方法来处理点击某个步骤时的事件。 7. 最后,在Vue组件的style中,可以定义一些样式来美化步骤条的外观。 这是一个简单的示例代码,展示了如何使用Vue2步骤条: ```html <template> <div> <steps :current="currentStep"> <step title="Step 1" description="This is step 1"></step> <step title="Step 2" description="This is step 2"></step> <step title="Step 3" description="This is step 3"></step> </steps> </div> </template> <script> import { Steps, Step } from 'vue2-steps'; export default { components: { Steps, Step }, data() { return { currentStep: 0 }; }, methods: { handleStepClick(index) { this.currentStep = index; } } }; </script> <style> /* 样式定义 */ </style> ``` 这样,你就可以在你的Vue应用中使用步骤条组件了。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值