Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. <!-- Timer Component -->
  2. <template>
  3. <span>{{ timer }}</span>
  4. </template>
  5.  
  6. <script>
  7.  
  8. props: {
  9. startTime: {
  10. type: String,
  11. default: '',
  12. },
  13. },
  14.  
  15. data () {
  16. return {
  17. now: Date.now (),
  18. bias: 0,
  19. }
  20. },
  21.  
  22. created () {
  23. this.runTimer ();
  24. },
  25.  
  26. computed: {
  27. timer () {
  28. return moment (this.now + this.bias).format ('YYYY/MM/DD HH:mm:ss');
  29. },
  30. },
  31.  
  32. methods: {
  33. runTimer () {
  34. let $vmc = this;
  35. setInterval (() => $vmc.now = Date.now (), 1000);
  36. }
  37. },
  38.  
  39. watch: {
  40. startTime () {
  41. if (this.start !== '')
  42. this.bias = moment (this.startTime).valueOf () - this.now;
  43. else this.bias = 0;
  44. }
  45. }
  46.  
  47. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement