Problem com $setState with events

I have a problem with events created through the page methods.
Example:

<script>  
  return {
    data: function () {
      return {        
        users: null
      }
    },
    methods: {
      selectUser: function(id,name,avatar){
        var self = this;
        var app = self.$app;

        localStorage.setItem('user_id', id);
        localStorage.setItem('user_name', name);
        localStorage.setItem('user_avatar', avatar);

        app.router.navigate('/check-lists/');
      },
      loadUsers: function(){
        var self = this;
        var app = self.$app;
        var params = self.$route.params;
        
        app.preloader.show();
        
        if(app.methods.checkInternet()){
          app.request.get(app.data.url+'api/v1/users/get-lists', {
            token: localStorage.getItem('token'),
            company_id: localStorage.getItem('company_id'),
            unit_id: localStorage.getItem('unit_id'),
          }, function (json) {          
            app.preloader.hide();
            
            self.$setState({
              users: json.data,
            }); 
          }, function(http, error){
            app.preloader.hide();
            app.methods.error(http);
          },'json');
        }
      },
    },
    on: {
      pageInit: function () {
        var self = this;
        
        self.loadUsers();
      },      
    }
  }
</script>

My Html

<ul class="profile__list">
          
          {{#each users}}
            <li class="profile__list__item">
              <a class="item-content item-link" @click="selectUser('{{id}}','{{name}}','{{avatar}}')">
                <div class="profile__list__item__person">
                  <div class="navbar__avatar"> 
                    <img class="navbar__avatar__item" src="{{ avatar }}" alt="">
                  </div>
                  <span class="profile__list__item__person__text">{{ name }}</span>
                </div>
               <span class="profile__list__item__office">Vendedor</span>
             </a>
            </li>
          {{/each}}
          
        </ul>

The method I currently have that is this: “selectUser”.
This method works only if I finish running the application and open the application again.

I do not know if this is an operating system problem (android) or if it is a bug in the framework.

However, I would like to know if there is a way to update the methods using the “$ setState”.

from where do you call the method selectUser ?

1 Like

My html:

<ul class="profile__list">
          
          {{#each users}}
            <li class="profile__list__item">
              <a class="item-content item-link" @click="selectUser('{{id}}','{{name}}','{{avatar}}')">
                <div class="profile__list__item__person">
                  <div class="navbar__avatar"> 
                    <img class="navbar__avatar__item" src="{{ avatar }}" alt="">
                  </div>
                  <span class="profile__list__item__person__text">{{ name }}</span>
                </div>
               <span class="profile__list__item__office">Vendedor</span>
             </a>
            </li>
          {{/each}}
          
        </ul>