[Vuejs]-Vuejs router.go(-1) not showing on second time

0πŸ‘

βœ…

I figure it out:

The problem was coming from socket.io. I’m checking if the event is bind already before to subscribe to a function and this function contains β€˜this’ that was still referring to the previous Vue instance.

Simply fixed by replacing this:

  //get rows 
    if (store.state.socket.io._callbacks["$rows"] == undefined) {
      console.log("Binding rows");
      //Where I receive the rows from API
      store.state.socket.io.on("rows", data => {
        console.log("rows reponse:", data);
        if (data.success) {
          this.nbrItems = data.rows.length;
          q.splice(0, q.length); //Clean the array without replacing the instance
          data.rows.map(a => q.push(a));
          console.log("Queue length: " + q.length);
        }
      });
    }

by this:

    if (store.state.socket.io._callbacks["$rows"] != undefined) {
      store.state.socket.io.off("rows");
    }
    console.log("Binding rows");
    store.state.socket.io.on("rows", data => {
      console.log("rows reponse:", data);
      if (data.success) {
        this.nbrItems = data.rows.length;
        q.splice(0, q.length);
        data.rows.map(a => q.push(a));
        console.log("Queue length: " + q.length);
      }
    });

But this makes me wonder, if I can still access to a previous Vue instance is it meaning that it will be some kind of memory leak with time?

I suppose that no with the garbage collector but would mean that nothing else refers to the previous instance.

0πŸ‘

Do you pop every element of the array before you call the created function?
I’m still an apprentice but it seems to me like you have to pop everything before adding new elements to the array.

Leave a comment