Count.vue
1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<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>