效果图

在这里插入图片描述

实现代码

 <div class="progress" @mousedown="onDragStart">
              <el-progress
                style="margin-top: 12px; cursor: pointer"
                :percentage="ruleForm.b"
              ></el-progress>
            </div>
<script>
export default {
  name: "add",
  data() {
    return {
      isDragEnd: false,
    };
  },
  created() {},
  mounted() {},
  methods: {
    onDragStart(event) {
      this.isDragEnd = true;
      const progressBox = this.$el.querySelector(".progress");
      progressBox.addEventListener("mouseup", this.onDragEnd);
      progressBox.addEventListener("mousemove", this.onDrag);
    },
    onDragEnd() {
      this.isDragEnd = false;
    },
    onDrag(event) {
      if (this.isDragEnd) {
        const progressBox = this.$el.querySelector(".progress");
        const rect = progressBox.getBoundingClientRect();
        const width = rect.width;
        const offsetX = event.clientX - rect.left;
        let percentage = Math.round((offsetX / width) * 100);
        percentage = Math.max(0, Math.min(percentage, 100));
        this.ruleForm.b = percentage;
      }
    },
  },
};
</script>
Logo

前往低代码交流专区

更多推荐