[Vuejs]-VueJs mounted nextTick function not being called

0๐Ÿ‘

โœ…

@Manan Vaghasiya gave the proper solution. Vue.js has a key prop that can be added to tell the Vue virtual DOM algorithm to treat each element as a separate item. In code, this looks like this:

<template v-for="item in items">
    <custom-element :key="something.unique" />
</template>

This will allow multiple instances of the same custom component to be swapped and not treated as the same object which allows the mounted/nextTick() function to run every time.

0๐Ÿ‘

If you use vue-router, then you can use afterEach function:

router.afterEach( ( to, from ) => {
  setTimeout( () => {
    document.body.scrollTop = 0;

  }, 100 );
} );

Full example you find here: https://github.com/tstabla/Vue.js-starter

Leave a comment