vue自己手写的步骤条组件

vue自己手写的步骤条组件,市面上的都不喜欢,满足不了功能,自己手写了个

效果
在这里插入图片描述
代码

<!-- 步骤条组件 -->
<template>
  <div style="
  width: 100%;
  display: flex;
    flex-direction: row;
    align-content: center;
    align-items: center;
    justify-content: space-around;">

    <div :class="singleDivClass(index , item)"
         @click="clickProgress(index, item)"
         v-for="(item,index) in progressList">{{ item.name }}

      <!-- 箭头-->
      <div v-if="progressList.length - 1 !== index"
           style="display: inline-block;position: absolute;right: -25px;height: 40px;width: 40px; z-index: 10">
        <div style="width: 25px;height: 20px;background-color: white;transform: skewX(30deg);"></div>
        <div style="width: 25px;height: 20px;background-color: white;transform: skewX(-30deg);"></div>
      </div>

    </div>

  </div>
</template>

<script>
export default {
  props: {
    progressList: {
      type: Array,
      default: [{
        name: '',  // 节点名称
        passed: true, // 是否通过,不通过的不让点
        checked: false // 是否当前节点
      }]
    },
  },
  name: "myProgressBar",
  components: {},
  data () {
    return {}
  },
  mounted () {
  },
  created () {
  },
  methods: {
    // 点击流程
    clickProgress (index, item) {

      if (!item.passed) {
        this.$message.info("请先处理上一步内容")
        return;
      }

      for (let i = 0; i < this.progressList.length; i++) {
        if (i === index) {
          this.$set(this.progressList[i], 'checked', true)
        } else {
          this.$set(this.progressList[i], 'checked', false)
        }
      }

      // 点击事件
      this.$emit('clickItem', index, item);

    },
    singleDivClass (index, item) {

      let resultClass;

      if (index === 0) {
        resultClass = 'left-redis-class'
      } else if (this.progressList.length - 1 === index) {
        resultClass = 'right-redis-class '
      }

      if (item.checked) {
        resultClass += '  single-div-class-checked';
      } else {
        resultClass += '  single-div-class';

        if (item.passed) {
          resultClass += '  single-div-background';
        } else {
          resultClass += ' single-div-background-disable';
        }

      }

      return resultClass;

    }

  },
  watch: {},
  computed: {}
}
</script>

<style lang="scss" scoped>

.left-redis-class {
  border-radius: 20px 0 0 20px;
}

.right-redis-class {
  border-radius: 0 20px 20px 0;
}


.single-div-background {
  background-color: #E6EEFA;
  cursor: pointer;

  &:hover {
    background-color: #d5e0f3;
  }
}

.single-div-background-disable {
  cursor: not-allowed;
  background-color: #e7e7e7;
}

.single-div-class {
  color: #0077CC;
  position: relative;
  flex: 1;
  height: 40px;
  font-size: 14px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}

.single-div-class-checked {
  color: #E6EEFA;
  position: relative;
  background-color: #0077CC;
  flex: 1;
  height: 40px;
  font-size: 14px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}

</style>



   <div style="padding: 20px;">
      <my-progress-bar
        :progressList="progressList"
        @clickItem="clickItem"></my-progress-bar> </div>```

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue3日期选择器可以通过以下步骤实现: 1. 创建一个名为DatePicker的Vue组件。 2. 在组件中定义一个data属性,包含所需的日期数据,例如当前日期、选择的开始日期和结束日期。 3. 在模板中创建日期选择器的界面,包括一个日历表格和选择按钮。 4. 在方法中实现选择日期的逻辑。可以通过按钮点击事件或者直接在日历表格中选择日期来触发选择逻辑。在选择日期后,更新开始日期和结束日期的值。 5. 在组件中定义一个computed属性,用于计算并返回选择的日期范围。 6. 在模板中使用v-model指令将选择的日期范围绑定到父组件的数据上。 以下是一个简单的Vue3日期选择器的示例代码: ``` <template> <div> <input type="text" v-model="selectedRange" readonly> <button @click="showCalendar">选择日期</button> <div v-if="showCalendar"> <!-- 日历表格 --> </div> </div> </template> <script> import { ref, reactive, computed } from 'vue'; export default { setup() { // 数据初始化 const selectedRange = ref(''); const showCalendar = ref(false); const startDate = ref(null); const endDate = ref(null); // 显示日历 const showCalendar = () => { showCalendar.value = true; }; // 选择日期 const selectDate = (date) => { if (!startDate.value) { startDate.value = date; } else if (!endDate.value) { if (date > startDate.value) { endDate.value = date; } else { endDate.value = startDate.value; startDate.value = date; } } else { startDate.value = date; endDate.value = null; } }; // 计算选择的日期范围 const selectedRange = computed(() => { if (startDate.value && endDate.value) { return `${startDate.value} - ${endDate.value}`; } else if (startDate.value) { return startDate.value; } else { return ''; } }); return { selectedRange, showCalendar, selectDate }; } }; </script> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值