Vue环形进度条

by DarcyAn

HTML

<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<div id="app">
<div class="pie-right">
<div class="right" :style="{transform: 'rotate(' + degRight + 'deg)'}">
</div>
<div class="mask">
</div>
</div>
<div class="pie-left">
<div class="left"  :style="{transform: 'rotate(' + degLeft + 'deg)'}">
</div>
<div class="mask">
</div>
</div>
</div>

CSS

.pie-right, .pie-left {
  position: absolute;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: yellow;
}
.right, .left {
  position: absolute;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: pink;
}
.pie-right, .right {
  clip: rect(0, auto, auto, 50px);
}
.pie-left, .left {
  clip: rect(0, 50px, auto, auto);
}

.mask {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: white;
}

JavaScript

var app = new Vue({
  el: '#app',
  data() {
    return {
      per: 0.3,
    }
  },
  computed: {
    degRight() {
      if(this.per <= 0.5) {
        return this.per*100*3.6
      } else {
        return 180
      }
    },
    degLeft() {
      if(this.per <= 0.5) {
        return 0
      } else {
        return this.per*100*3.6 - 180
      }
    },
  },
})