|
| 1 | +<template> |
| 2 | + <div class="components-container"> |
| 3 | + <code>countTo 组件 <a href='https://github.com/PanJiaChen/vue-countTo' target='_blank'>线上地址</a></code> |
| 4 | + |
| 5 | + <count-to ref='example' class='example' :start-val='_startVal' :end-val='_endVal' :duration='_duration' :decimals='_decimals' |
| 6 | + :separator='_separator' :prefix='_prefix' :suffix='_suffix' :autoplay='false' /> |
| 7 | + <div style='margin-left: 25%;margin-top: 40px;'> |
| 8 | + <label class="label" for="startValInput">startVal: <input type="number" v-model.number='setStartVal' name='startValInput' /></label> |
| 9 | + <label class="label" for="endValInput">endVal: <input type="number" v-model.number='setEndVal' name='endVaInput' /></label> |
| 10 | + <label class="label" for="durationInput">duration: <input type="number" v-model.number='setDuration' name='durationInput' /></label> |
| 11 | + <div class="startBtn example-btn" @click='start'>开始</div> |
| 12 | + <div class="pause-resume-btn example-btn" @click='pauseResume'>暂停/恢复</div> |
| 13 | + <br/> |
| 14 | + <label class="label" for="decimalsInput">decimals: <input type="number" v-model.number='setDecimals' name='decimalsInput' /></label> |
| 15 | + <label class="label" for="separatorInput">separator: <input v-model='setSeparator' name='separatorInput' /></label> |
| 16 | + <label class="label" for="prefixInput">prefix: <input v-model='setPrefix' name='prefixInput' /></label> |
| 17 | + <label class="label" for="suffixInput">suffix: <input v-model='setSuffix' name='suffixInput' /></label> |
| 18 | + </div> |
| 19 | + <code><count-to :start-val='{{_startVal}}' :end-val='{{_endVal}}' :duration='{{_duration}}' :decimals='{{_decimals}}' |
| 20 | + :separator='{{_separator}}' :prefix='{{_prefix}}' :suffix='{{_suffix}}' :autoplay=false></code> |
| 21 | + </div> |
| 22 | +</template> |
| 23 | +<script> |
| 24 | + import countTo from 'vue-count-to'; |
| 25 | +
|
| 26 | + export default { |
| 27 | + components: { countTo }, |
| 28 | + data() { |
| 29 | + return { |
| 30 | + setStartVal: 0, |
| 31 | + setEndVal: 2017, |
| 32 | + setDuration: 4000, |
| 33 | + setDecimals: 0, |
| 34 | + setSeparator: ',', |
| 35 | + setSuffix: ' rmb', |
| 36 | + setPrefix: '¥ ' |
| 37 | + } |
| 38 | + }, |
| 39 | + computed: { |
| 40 | + _startVal() { |
| 41 | + if (this.setStartVal) { |
| 42 | + return this.setStartVal |
| 43 | + } else { |
| 44 | + return 0 |
| 45 | + } |
| 46 | + }, |
| 47 | + _endVal() { |
| 48 | + if (this.setEndVal) { |
| 49 | + return this.setEndVal |
| 50 | + } else { |
| 51 | + return 0 |
| 52 | + } |
| 53 | + }, |
| 54 | + _duration() { |
| 55 | + if (this.setDuration) { |
| 56 | + return this.setDuration |
| 57 | + } else { |
| 58 | + return 100 |
| 59 | + } |
| 60 | + }, |
| 61 | + _decimals() { |
| 62 | + if (this.setDecimals) { |
| 63 | + if (this.setDecimals < 0 || this.setDecimals > 20) { |
| 64 | + alert('digits argument must be between 0 and 20') |
| 65 | + return 0 |
| 66 | + } |
| 67 | + return this.setDecimals |
| 68 | + } else { |
| 69 | + return 0 |
| 70 | + } |
| 71 | + }, |
| 72 | + _separator() { |
| 73 | + return this.setSeparator |
| 74 | + }, |
| 75 | + _suffix() { |
| 76 | + return this.setSuffix |
| 77 | + }, |
| 78 | + _prefix() { |
| 79 | + return this.setPrefix |
| 80 | + } |
| 81 | + }, |
| 82 | + methods: { |
| 83 | + start() { |
| 84 | + this.$refs.example.start(); |
| 85 | + }, |
| 86 | + pauseResume() { |
| 87 | + this.$refs.example.pauseResume(); |
| 88 | + } |
| 89 | + } |
| 90 | + }; |
| 91 | +</script> |
| 92 | + |
| 93 | +<style scoped> |
| 94 | +.example-btn { |
| 95 | + display: inline-block; |
| 96 | + margin-bottom: 0; |
| 97 | + font-weight: 500; |
| 98 | + text-align: center; |
| 99 | + -ms-touch-action: manipulation; |
| 100 | + touch-action: manipulation; |
| 101 | + cursor: pointer; |
| 102 | + background-image: none; |
| 103 | + border: 1px solid transparent; |
| 104 | + white-space: nowrap; |
| 105 | + line-height: 1.5; |
| 106 | + padding: 4px 15px; |
| 107 | + font-size: 12px; |
| 108 | + border-radius: 4px; |
| 109 | + -webkit-user-select: none; |
| 110 | + -moz-user-select: none; |
| 111 | + -ms-user-select: none; |
| 112 | + user-select: none; |
| 113 | + -webkit-transition: all .3s cubic-bezier(.645, .045, .355, 1); |
| 114 | + transition: all .3s cubic-bezier(.645, .045, .355, 1); |
| 115 | + position: relative; |
| 116 | + color: rgba(0, 0, 0, .65); |
| 117 | + background-color: #fff; |
| 118 | + border-color: #d9d9d9; |
| 119 | +} |
| 120 | +
|
| 121 | +.example-btn:hover { |
| 122 | + color: #4AB7BD; |
| 123 | + background-color: #fff; |
| 124 | + border-color: #4AB7BD; |
| 125 | +} |
| 126 | +.example { |
| 127 | + font-size: 50px; |
| 128 | + color: #F6416C; |
| 129 | + display: block; |
| 130 | + margin: 10px 0; |
| 131 | + text-align: center; |
| 132 | + font-size: 80px; |
| 133 | + font-weight: 500; |
| 134 | +} |
| 135 | +
|
| 136 | +.label { |
| 137 | + color: #2f4f4f; |
| 138 | + font-size: 16px; |
| 139 | + display: inline-block; |
| 140 | + margin: 15px 30px 15px 0; |
| 141 | +} |
| 142 | +
|
| 143 | +input { |
| 144 | + position: relative; |
| 145 | + display: inline-block; |
| 146 | + padding: 4px 7px; |
| 147 | + width: 70px; |
| 148 | + height: 28px; |
| 149 | + cursor: text; |
| 150 | + font-size: 12px; |
| 151 | + line-height: 1.5; |
| 152 | + color: rgba(0, 0, 0, .65); |
| 153 | + background-color: #fff; |
| 154 | + background-image: none; |
| 155 | + border: 1px solid #d9d9d9; |
| 156 | + border-radius: 4px; |
| 157 | + -webkit-transition: all .3s; |
| 158 | + transition: all .3s; |
| 159 | +} |
| 160 | +
|
| 161 | +.startBtn { |
| 162 | + margin-left: 20px; |
| 163 | + font-size: 20px; |
| 164 | + color: #30B08F; |
| 165 | + background-color: #fff; |
| 166 | +} |
| 167 | +
|
| 168 | +.startBtn:hover { |
| 169 | + background-color: #30B08F; |
| 170 | + color: #fff; |
| 171 | + border-color: #30B08F; |
| 172 | +} |
| 173 | +
|
| 174 | +.pause-resume-btn { |
| 175 | + font-size: 20px; |
| 176 | + color: #E65D6E; |
| 177 | + background-color: #fff; |
| 178 | +} |
| 179 | +
|
| 180 | +.pause-resume-btn:hover { |
| 181 | + background-color: #E65D6E; |
| 182 | + color: #fff; |
| 183 | + border-color: #E65D6E; |
| 184 | +} |
| 185 | +</style> |
| 186 | + |
| 187 | + |
0 commit comments