Count.vue 1.69 KB
<template>
  <div class='count-box'>
    <div
      v-for='(i,index) in numbers'
      :key='index'
      class='count-item'
    >

      <div
        class='number-box'
        :style="{'top':`-${i * 100}%`}"
      >
        <div
          v-for='(n,ind) in num'
          :key='ind'
        >{{n}}</div>
      </div>
    </div>
  </div>
</template>

<script type='text/ecmascript-6'>
import countTo from "vue-count-to"
export default {
  name: 'Count',
  components: {
    countTo
  },
  props: {
    number: {
      type: Number,
      default: 11
    }
  },
  data () {
    return {
      numbers: [],
      num: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    }
  },
  methods: {

  },
  watch: {
    'number' (newVal, oldVal) {
      if (newVal) {
        newVal = newVal.toString().split('')
        this.numbers = []
        this.setNumber(newVal)
      }
    }
  },
  mounted () {
    this.number = this.number.toString().split('')
    this.setNumber(this.number)
  },
  methods: {
    setNumber (data) {
      data.forEach(e => {
        this.numbers.push(
          Number(e)
        )
      })
    }
  }
}
</script>

<style scoped lang='scss'>
.count-box {
  text-align: center;
  padding-top: 15px;
  margin-bottom: 61px;
  font-size: 0;
  .count-item {
    display: inline-block;
    width: 94px;
    height: 150px;
    line-height: 150px;
    font-size: 80px;
    margin-right: 5px;
    font-weight: 700;
    background: url("~@a/count-box.png") no-repeat;
    background-size: cover;
    position: relative;
    overflow: hidden;
    .number-box {
      position: absolute;
      width: 100%;
      height: 100%;
      left: 0;
      transition: all 0.1s;
    }
  }
}
.count-item:last-of-type {
  margin-right: 0;
}
</style>