Skip to content
Advertisement

How to handle the change of the previous object

I’m currently making a nav bar. I create an array storing the info of the tabs in the nav bar.

JavaScript

When a new route is clicked it updates the newly clicked tab to allow the current property to be true.

How would you change the previous nav item to false. As currently they all change to true one by one as they are clicked.

I think if I store a value as previous

JavaScript

This is what i’ve got atm, it has to go around 3 routes ahead till the one before vanishes…

JavaScript

Advertisement

Answer

Create a watcher on the route name

JavaScript

Usually you can just use the watcher routeName value above to run whatever side effect you want but if tracking current on each tab is really necessary the above code will get the job done.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement