timer.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template>
  2. <text class="time">{{ showTime }}</text>
  3. </template>
  4. <script>
  5. export default {
  6. name: "timer",
  7. data() {
  8. return {
  9. showTime: "00:00:00",
  10. count: null,
  11. scale: 60
  12. }
  13. },
  14. methods: {
  15. startCounting() {
  16. let time = this.showTime.split(":");
  17. this.count = setInterval(() => {
  18. if (time[2] == this.scale) {
  19. if (time[1] == this.scale) {
  20. time[0] = time[0] - 0 + 1;
  21. time[1] = '00';
  22. } else {
  23. time[1] = time[1] - 0 + 1;
  24. }
  25. time[2] = '00';
  26. } else {
  27. time[2] = time[2] - 0 + 1;
  28. }
  29. this.showTime = time.map(v => v != '00' && v < 10 ? '0' + v : v).join(":")
  30. }, 1000);
  31. },
  32. endTiming() {
  33. clearInterval(this.count);
  34. return this.showTime;
  35. },
  36. getTime(){
  37. return this.showTime;
  38. }
  39. },
  40. }
  41. </script>
  42. <style lang="scss"></style>