G
G
GrimJack2017-10-05 19:03:29
JavaScript
GrimJack, 2017-10-05 19:03:29

How to keep track of route parameters updates?

Given:

vue-router
{
        path: '/data-list/:list_slug',
        name: 'data_list',
        component: data_list,
        meta: {
            requiresAuth: true,
            breadcrumbs: [
                {
                    'url': 'data_list',
                    'title': 'Data'
                },
                {
                    'title': ''
                }
            ]
        },
        children: [
            {
                path: ':list_id',
                name: 'data_list.edit',
                component: data_list
            }
        ]

    }

It is necessary to follow the update inside the component. :list_slug
I can't figure out how to do it. I tried to assign it as a variable in data(){return{***}} and make a deep watch but it didn't help. How can this be done? Google did not help (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Velko, 2017-10-05
@GrimJack

Try like this:

watch: {
  '$route.params.list_slug': function (listSlug) {
    console.log(listSlug); // выводим новое значение параметра роута
    this.doSomething(); // выполняете что нужно
  },
},

You can also "follow" the route object in its entirety:
watch: {
  '$route': function (to, from) {
    // выполняем что-либо, когда роут меняется
  },
},

Similar examples are described in the documentation .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question