[Vuejs]-Vuejs router listen to events

4👍

If I understood your question correctly, the listening component would be the <router-view>, so:

<router-view @reset-invoice="resetInvoice"></router-view>

And in whichever component this router view is rendered:

{
  methods: {
    resetInvoice() {
      // ...
    }
  }
}

0👍

You should watch the route and set the props passed from the route, like below

watch: {
    '$route' (to, from) {
          this.user_id = this.$route.params.id
    },     
}

0👍

It seems I’m too late but in case someone needed it.

created() {
    // watch the params of the route to fetch the data again
    this.$watch(
      () => this.$route.params,
      () => {
        //perform here your awesome logic
      },
      // fetch the data when the view is created and the data is
      // already being observed
      { immediate: true }
    )
  },

Leave a comment