[Vuejs]-Reinit javascript function when change view in vue js

0๐Ÿ‘

On mounted trigger you can add your custom js for each component

<script>
    export default {
        mounted () {

        }
    }
</script>

0๐Ÿ‘

if anyone stumbles upon this and still looking for a way to do it, this is how I managed to do this. wrap the <route-view/> in a <transition> which you can control with css and call a method on enter which calls the function you want.
this will call the function as soon as the component is loaded in the DOM on every route change

<transition name="slide" v-on:enter="reInitJS">
   <router-view></router-view>
</transition>

<script>
//import the wanted function
import {init} from './main';
export default {
  name: 'App', 
  methods: {
    reInitJS(){
    //call the function
      init(); 
    }
  }
}
</script>

Leave a comment