vue3+Ts 按项目需求自定义van-steps步骤条

在Vant中的steps所提供的样式类型相对来说过于基础,当我们需要一些别的样式时就得更具Vant所提供的API来进行自定义。

以下我会给到大家一些实用性比较高的的自定义

以下是实现上图效果的代码

<template>
  <div class="content">
    <van-nav-bar title="达标进度" left-arrow @click-left="router.back()" fixed />
    
          <!-- active-icon 这里可以用作进行中状态 -->
          <van-steps class="ml-2 mr-2" :active="active" :active-icon="successIcon(2)"  inactive-color="#e5e5e5" active-color="#eb4662">
            <van-step v-for="item in 5" :class='`step${item}`' :key="item">
              <template #inactive-icon>
                <div class="flex justify-center"><van-image width="32" fit="cover" :src="successIcon(3)" /></div>
              </template>+
              <template #finish-icon>//已完成步骤有两种状态根据接口参数设置
                <div v-if="item==1 " class="flex justify-center"><van-image width="32" fit="cover" :src="successIcon(1)" /></div>
                <div v-else class="flex justify-center"><van-image width="32" fit="cover" :src="successIcon(0)" /></div>
              </template>
              <span :class="active > item ? 'text-[#400f0d]' : ''">2024年4月</span>
            </van-step>
          </van-steps>
  </div>

</template>

<script setup>
import { ref, onActivated } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/stores'
const userStore = useUserStore()
const router = useRouter()
const active = ref(3)
onActivated(() => {
})
const successIcon = (val) => {//按需传参变更图标
  let index = ''
  switch (Number(val)) {
    case 0:
      index = `/src/assets/images/state_1.png`
      break;
    case 1:
      index = `/src/assets/images/state_2.png`
      break;
    case 2:
      index = `/src/assets/images/state_3.png`
      break;
    case 3:
      index = `/src/assets/images/state_4.png`
      break;
  }
  return index
}



</script>
<style lang="less" scoped>
.content {
  background-image: url('/src/assets/images/speed_bg.png');
  background-size: cover;
  background-repeat: no-repeat;
  overflow: hidden;
}



/deep/.van-step__line {
  border: dashed 1px #fff;
  // width: 120px !important;

}

/deep/.van-steps--horizontal {
  padding: 10px;
  background-color: #ffffff00;
  // width: 300px; 
  // overflow: hidden;
}

/deep/.van-step__title {
  margin-top: 50px;
  margin-left: 6px;
  margin-right: 12px;
}

.step1 {
  /deep/.van-step__title {
    margin-top: 50px;
    margin-left: -10px;
  }
}

.step5 {
  /deep/.van-step__title {
    margin-top: 50px;
    margin-right: -13px;

    >span {
      word-break: break-word;
      width: 58px;
      display: inline-block;
    }
  }
}

/deep/.van-step__circle-container {
  padding: 0px 4px;
}

.van-steps {
  /deep/.van-icon__image {
    width: 2rem;
    height: 2rem;
  }
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值