Guest User

Untitled

a guest
Feb 25th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. <html>
  2. ...code
  3.  
  4. <script>
  5.  
  6. var app = new Vue({
  7. el: '#app',
  8. data() {
  9. return {
  10. running: false,
  11. timer: 0,
  12. formattedTime: "00:00:00",
  13. interval: null,
  14. sessions: [
  15. { name: 'Initial State', time: '22:15:21' }
  16. ]
  17. }
  18. },
  19.  
  20. methods: {
  21. toggleTimer: function() {
  22. if (this.running) {
  23. // change state to not running
  24. this.running = false;
  25.  
  26. // stop the interval
  27. clearInterval(this.interval);
  28.  
  29. // save current session
  30. this.saveSession();
  31.  
  32. // reset timer
  33. this.timer = 0;
  34. this.formattedTime = '00:00:00';
  35.  
  36. // finish function execution
  37. return;
  38. }
  39.  
  40. // if it is not running (running = false)
  41. // change state to running
  42. this.running = true;
  43.  
  44. // the interval
  45. this.interval = setInterval(function() {
  46. this.timer++; // increase the timer with 1 (1 second)
  47. this.formattedTime = this.convertSecondsToTime(this.timer);
  48. }.bind(this), 1000) // 1000 ms = 1 second
  49. },
  50.  
  51. convertSecondsToTime: function(seconds) {
  52. var date = new Date(null);
  53.  
  54. date.setSeconds(seconds);
  55. return date.toISOString().substr(11, 8);
  56. },
  57.  
  58. saveSession: function() {
  59. // todo
  60. }
  61. }
  62.  
  63.  
  64. });
  65. </script>
  66. </body>
  67. </html>
Add Comment
Please, Sign In to add comment