[SOLVED] Framework7 v2 component: Set value of Data


#1

Hi everyone, I have a problem… I change/set value of data in my component page, and its ok, it work fine, but when I go to another page, and go back to the first page, the data that I change is with de default data from init.

Data:

data: function () {
      return {
             name: "test",
      }
 },

On init:

 on: {
        pageInit: function (e, page) {
               var self = this;
               if (self.$root.infoUsuarioLogueado) {
                   var infoUsuario = self.$root.infoUsuarioLogueado;
                   self.$setState({
                        name: infoUsuario.nombres + " " + infoUsuario.apellidos
                    });
                    self.name= infoUsuario.nombres + " " + infoUsuario.apellidos; 
                }
         }
  }

I enter and leave the page with navigate method, like this:

this.$router.navigate('/inicio/', {
                    animate: true,
                    pushState: false
                });

Thanks before after all.


#2

Next time component loaded it will be initialized from the beginning. So you need to store it to some global variable and retreive it on component creation, something like here [V3 Vue] Prevent destroy of component on back click


#3

Thanks for the quick response, so I set variables with $setState in PageInit, and store values in $root.
Thanks you!!