vue百分比组件 - 传进来的数据是百分比才可以

在这里插入图片描述

<template>
  <div class="cruiseTaxi">
    <div class="cruiseTaxi-title">{{ title }}</div>
    <div class="cruiseTaxi-con" :style="{borderColor:color}" v-if="isshowHeavyLoad||isshowNoLoad">
      <div class="cruiseTaxi-con_left" :style="{width:heavyLoad,background:color}" v-if="isshowHeavyLoad" @mousemove="handleHeavyLoadEnter($event,heavyLoad)" @mouseout="handleHeavyLoadLeave">数据一</div>
      <div class="cruiseTaxi-con_right" :style="{width:noLoad,color:color}" v-if="isshowNoLoad" @mousemove="handleNoLoadEnter($event,noLoad)" @mouseout="handleNoLoadLeave">数据二</div>
      <div v-if="popisShow" id="pop" :style="{top:offsetY+'px',left:offsetX+'px'}" style="position: absolute;z-index: 1;">{{ val }}</div>
    </div>
    <div v-if="!(isshowHeavyLoad||isshowNoLoad)" class="emptyName">暂无数据</div>
  </div>
</template>

<script>
export default {
  name: "cruiseTaxi",
  props: {
    title: {
      type: String,
      default: "",
    },
    heavyLoad: {
      type: String,
      default: "",
    },
    noLoad: {
      type: String,
      default: "",
    },
    color: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      isshowHeavyLoad: false,
      isshowNoLoad: false,
      val: "123",
      popisShow: false, //鼠标经过的弹窗是否显示
      offsetX: 0,
      offsetY: 0,
    };
  },
  created() {},
  watch: {
    heavyLoad(newVal) {
      let ele = newVal.slice(0, -1);
      if (ele === "null" || ele === "undefined" || ele.length == 0||ele ==0) {
        this.isshowHeavyLoad = false;
      } else {
        this.isshowHeavyLoad = true;
      }
    },
    noLoad(newVal) {
      let ele = newVal.slice(0, -1);
      if (ele === "null" || ele === "undefined" || ele.length == 0||ele==0) {
        this.isshowNoLoad = false;
      } else {
        this.isshowNoLoad = true;
      }
    },
  },
  methods: {
    // 重载鼠标移入
    handleHeavyLoadEnter(e, val) {
      this.popisShow = true;
      this.offsetX = e.layerX + 10;
      this.offsetY = e.layerY + 22;
      this.val = "数据一" + val;
    },
    // 重载鼠标移出
    handleHeavyLoadLeave() {
      this.popisShow = false;
    },
    // 空载鼠标移入
    handleNoLoadEnter(e, val) {
      this.popisShow = true;
      this.offsetX = e.layerX + 10;
      this.offsetY = e.layerY + 22;
      this.val = "数据二" + val;
    },
    // 空载鼠标移出
    handleNoLoadLeave() {
      this.popisShow = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.cruiseTaxi {
  margin-top: 20px;
  .cruiseTaxi-title {
    font-size: 14px;
    font-weight: 700;
  }
  .emptyName {
    margin-top: 10px;
    height: 40px;
    line-height: 40px;
    color: #84888c;
    text-align: center;
    border: 1px solid #dee1e6;
    border-radius: 4px;
  }
  .cruiseTaxi-con {
    height: 40px;
    line-height: 40px;
    margin-top: 10px;
    display: flex;
    border: 1px solid #3886ff;
    border-radius: 4px;
    text-align: center;
    font-size: 12px;
    position: relative;
    #pop {
      padding: 0px 10px;
      background: rgba(0, 0, 0, 0.5);
      border-radius: 6px;
      color: #fff;
      min-width: 80px;
      white-space: nowrap;
    }
    .cruiseTaxi-con_left {
      background: #3886ff;
      border-bottom-right-radius: 4px;
      border-top-right-radius: 4px;
      color: #fff;
      min-width: 4%;
    }
    .cruiseTaxi-con_left:hover {
      cursor: pointer;
    }
    .cruiseTaxi-con_right{
      min-width: 4%;
    }
    .cruiseTaxi-con_right:hover {
      cursor: pointer;
    }
  }
}
</style>

传进来的数据是百分比才可以

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值