Timers and other features for Heroes of the Storm
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 

54 рядки
1.2 KiB

  1. <template>
  2. <div class="timer">
  3. <span v-if="displayHours">{{ hours }}:</span><span v-if="displayMinutes">{{ minutes }}</span><span>:{{ seconds }}</span>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'Timer',
  9. data () {
  10. return {
  11. currentTime: this.$attrs.initialTime
  12. }
  13. },
  14. methods: {
  15. startTimer: function () {
  16. this.timerIntevalId = setInterval(() => {
  17. this.currentTime--
  18. if (this.currentTime === 0) {
  19. this.stopTimer()
  20. }
  21. }, 1000)
  22. },
  23. stopTimer: function () {
  24. clearInterval(this.timerIntevalId)
  25. }
  26. },
  27. computed: {
  28. seconds: function () {
  29. return (this.currentTime % 60).toLocaleString('en', {minimumIntegerDigits: 2})
  30. },
  31. minutes: function () {
  32. return (Math.floor(this.currentTime / 60) % 60)
  33. },
  34. hours: function () {
  35. return (Math.floor(this.currentTime / 3600) % 24)
  36. },
  37. displayMinutes: function () {
  38. return this.minutes > 0 || this.hours > 0
  39. },
  40. displayHours: function () {
  41. return this.hours > 0
  42. }
  43. },
  44. mounted () {
  45. this.startTimer()
  46. }
  47. }
  48. </script>
  49. <style scoped>
  50. </style>