D
D
dark_king_132019-12-25 20:54:15
Vue.js
dark_king_13, 2019-12-25 20:54:15

Vue.js How to update a component called in App.vue in a route?

In App.js, I have a Menu component called, to which a set of links is sent. There are 2 sets, one for a registered user, the other for an unregistered one.
App.vue has the following code:
5e03b0f2d6fe7236675537.png
5e03b0f7f4086714052690.png
But its problem is that the menu is updated only when the page is completely reloaded, and I need that when, after authorization, the user is redirected to the main page, the set of links is updated.
Calling location.reload() on the LogIn and LogOut components solves this problem, but adds a new reload itself. What other options are there to solve the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aetae, 2019-12-25
@dark_king_13

LocalStorage itself is not reactive, so your computed doesn't make much sense.
In a good way, token just needs to be stored in a reactive store (not necessarily vuex, you can just observable), and in all places you can receive and put it through this store. Then everything will work out of the box.
If the token arrives in localStorage from somewhere by itself, then you will have to hang up the onstorage event and catch changes manually in the right places.

V
VegasChickiChicki, 2019-12-25
@VegasChickiChicki

Why is this data in mounted? Just put them in data, what's the problem?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question