Page event scope variables


#1

Hi. I want to access an interval variable from seperate page events. Can I access a variable(created in page:init) from page:BeforeOut?

Actualy I want to stop an interval when leaving from page.


#2

if you have ever used vue, you will find this so similar and easy… I think the best way to do it is using the core component router. It has lifecycle hooks… Just read through and get the whole picture. It will help you structure your code in the most possible way.

You could something like:

<template>
  ...
</template>

<style>
...
</style>

<script>
return {
      // Component Data
data: function () {
  // Must return an object
  return {
    checker: null, //to handle interval
  }
},
// Component Methods
methods: { 
  ...

     destroyChecker: function(){
        var self = this;

         self.$setState({
            checker: clearInterval(self.checker)
         });
        
      },
},
//Page Events
on: {
   pageInit: function(e, page){
      ....//do something on page init
   },
   pageAfterIn: function(e, page) {

      var self = this;
      var app = self.$app;

    //start your interval after page is in

      self.$setState({
          checker: setInterval(function(){ 
                ...start something...
          },5000)
    });
  },

  pageBeforeOut: function(e, page) {
      var self = this;
         //let's destroy the interval now
      self.destroyChecker();
  },
 }
}
</script>