V6: events triggers more than 1 time

Hello,

I’m migrating a mid-developed app to v6.

In app.f7.html I handdle the pageInit and panel:opened events in that way:

$on('pageInit', (e, page) => {
  console.log("page_init");
  $('.panel-left').on('panel:opened', function () {
    console.log('panel_left_opened');
    if (menus.value.length == 0) {
      loadMenus();
    }
  });
});

And the first time i open the app the pageInit triggers 3 times instead of only 1, when I open the panel first time it triggers 3 times too, and while using the app, the panel:opened event increases littel by little triggerind 5…6…7… times or even more… instead only 1 every single time I open the left panel…

I’ve not tested yet if this happens on other events in the app…

This is exactly what your code does. In your code with EVERY page init, you add one more event listener to panel:opened event

I’ve added the code:

$on('pageBeforeRemove', (e, page) => {
  $('.panel-left').off("panel:opened");
});

The pageInit triggers 3 times at the first time I enter the app, and first time I open the panel the panel:opened event triggers 3 times too loading 3 times the menú to the database, then i navigate to other pages in the app and returning to the home page panel:opened doesn’t trigger anymore…
Why the pageInit triggers 3 times?
so if I dont enter the panel first time and navigate to other pages not in the menu, the event panel:openend is removed and the menu never loads, because it’s loaded on first panel:opened event.
I’m working on app.f7.html page

I guess because you have 3 pages in your app, pageInit is not appropriate place to add panel:open event listener

Ok, thanks Vladimir, i’ll investigate to do it in other way, thanks for the advices.