123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <template>
- <text class="time">{{ showTime }}</text>
- </template>
- <script>
- export default {
- name: "timer",
- data() {
- return {
- showTime: "00:00:00",
- count: null,
- scale: 60
- }
- },
- methods: {
- startCounting() {
- let time = this.showTime.split(":");
- this.count = setInterval(() => {
- if (time[2] == this.scale) {
- if (time[1] == this.scale) {
- time[0] = time[0] - 0 + 1;
- time[1] = '00';
- } else {
- time[1] = time[1] - 0 + 1;
- }
- time[2] = '00';
- } else {
- time[2] = time[2] - 0 + 1;
- }
- this.showTime = time.map(v => v != '00' && v < 10 ? '0' + v : v).join(":")
- }, 1000);
- },
- endTiming() {
- clearInterval(this.count);
- return this.showTime;
- },
- getTime(){
- return this.showTime;
- }
- },
- }
- </script>
- <style lang="scss"></style>
|