[Vuejs]-Why the slice method doesn't work on array prop?

0👍

This is a tricky thing about console.log().
console.log(pokeStore.pokemonsLoaded) will show you the result of the fetched data even if console.log is in reality executed before the fetch is done. This is due to the fact that many browsers show a "live" view of object data.

https://developer.mozilla.org/en-US/docs/Web/API/Console/log#logging_objects

Don’t use console.log(obj), use console.log(JSON.parse(JSON.stringify(obj))) … many browsers provide a live view that constantly updates as values change. This may not be what you want.

It is probable then that the array has not actually been updated at the time you slice it. I also believe this is true because even though you await this call: await pokeStore.loadPokemons(...), that function does not await it’s call to loadPokemon(). Since there is no await, the function immediately finishes executing before the fetch has finished and returns to your component code.

I believe if you do await that call, everything should start working

async function loadPokemons(offset, limit){
  .
  .
  .
  await loadPokemon(pokemonsList.value[i].name)
}

Leave a comment