title: Clear Interval doesn't work in VUE
body: <p>I am trying to build a Pomodoro Timer using VUE.js, below is the relevant code snippet that I had problems on. So the problem is that the clearInterval Method doesn't seem to work here. </p>
  
  <pre><code>   data: {
          workTimeInMin: 1,
          breakTimeInMin: 1,
          timeRemainInMillisecond: 0,
          timerOn: false,
          rest: false
        },
  
        methods: {
          startOrStopTheTimer: function() {
            var self = this;
            var interval;
            if (this.timerOn){
              this.timerOn = !this.timerOn;
              window.clearInterval(interval);
              console.log("clearInterval");
            }else {
              this.timerOn = !this.timerOn;
              interval = setInterval(function(){
              console.log("123");
              if (self.timeRemainInMillisecond &lt;= 0) {
                console.log("1");
                self.rest = !self.rest;
                if (self.rest) {
                  self.timeRemainInMillisecond = self.restTimeInMin*60*1000;
                }else {
                  self.timeRemainInMillisecond = self.workTimeInMin*60*1000;
                }
              }
                this.timeRemainInMillisecond = this.timeRemainInMillisecond-1000
              }, 1000);
            }
          },
  </code></pre>
  
  <p><a href="https://codepen.io/ge524119574/full/EXVbWB/" rel="nofollow noreferrer">You can find a live demo here.</a></p>
  
  <p>In the page, when I click start an set Interval method is called. Then I clicked the stop, it is supposed to clear the interval, however it doesn't seem to work as I intend it to. You can inspect the console and easily find the "123" keeps popping up which indicates that the interval is not cleared.</p>
  
  <p>After searching a while in the StackOverFlow, I found that if I define the variable <code>interval</code> to in the global context it will work as I intend it. But I wish to know why it is so.</p>
  
  <p>Your help will be highly appreciated. Thanks in advance!</p>