步骤条组件

最近做了一个步骤条组件,使用的是vue3语法,vue2请自己做兼容

先上样式

<template>
  <!-- 步骤条 -->
  <view class="box-top" v-for="(item, index) in dataArray" :key="index">
    <view class="left-box-top">{{ item.createTime }}</view>
    <!-- 左边 -->
    <view
      class="line"
      :class="{ active: item.active, none: index == dataArray.length - 1 }"
    >
      <!-- 中线 -->
      <view class="dot" :class="{ active: item.active }"></view>
      <!-- 圆点 -->
    </view>
    <view class="right-box-top">
      <!-- 右边 -->
      <view>{{ item.msg }}</view>
    </view>
  </view>
</template>

<script setup>
import { defineProps, watch, reactive } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
const props = defineProps({
  dataArray: {
    type: Array,
  },
});
watch(
  () => props.dataArray,
  (newValue, oldValue) => {
    console.log('数据变化了', newValue);
    if (newValue) {
      if (props.dataArray[0]) {
        Object.assign(props.dataArray[0], {
          active: true,
        });
      }
    }
  },
  {
    deep: true,
    immediate: true,
  },
);
onLoad(() => {
  console.log(props.dataArray);
});
</script>

<style lang="scss">
.box-top {
  width: 100%;
  min-height: 120rpx;
  box-sizing: border-box;
  display: flex;
  flex-direction: row;

  .left-box-top {
    width: 180rpx;
    text-align: center;
    color: rgba(198, 198, 198, 1);
    font-size: 24rpx;
  }

  .line {
    width: 4rpx;
    background-color: #999999;
    margin: 0 20rpx 0 20rpx;

    .dot {
      width: 20rpx;
      height: 20rpx;
      border: 1rpx solid #979797;
      background-color: #ffffff;
      border-radius: 50%;
      position: relative;
      left: -10rpx;
    }
  }

  .right-box-top {
    flex: 1;
    padding: 0 0 20rpx 0;
    font-size: 24rpx
  }
}

//激活元素
.active {
  background: #161874 !important;
}

// 隐藏元素
.none {
  background-color: rgba(0, 0, 0, 0) !important;
}
</style>

使用

<Step :dataArray="你想传的数据" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值