How to make the directives react on state changes?
See original GitHub issueI am using vue-browser-acl’s custom directive as such:
<template>
<div>
<BaseSideNavigationMenu v-role:authenticated />
<PageContent />
</div>
</template>
With the following setup and rule:
Vue.use(Acl, store.state.currentUser, (acl) => acl.rule("authenticated", () => store.getters.isAuthenticated));
And the following in my store:
export default new Vuex.Store({
state: {
currentUser: JSON.parse(window.localStorage.getItem("currentUser") || "{}"),
},
mutations: {
SET_CURRENT_USER(state, user) {
state.currentUser = user;
window.localStorage.setItem("currentUser", JSON.stringify(user));
},
SET_NO_CURRENT_USER(state) {
state.currentUser = {};
window.localStorage.setItem("currentUser", "{}");
},
},
actions: {
async login({ commit }, login_data) {
try {
const response = await axios.post("/api/login", login_data);
const currentUser = response.data.currentUser
commit("SET_CURRENT_USER", currentUser);
return response;
}
},
async logout({ commit }) {
const response = await axios.post("/api/logout");
commit("SET_NO_CURRENT_USER");
},
},
getters: {
isAuthenticated(state) {
return Object.keys(state.currentUser).length > 0;
}
},
However, when a user does a login
, the <BaseSideNavigationMenu v-role:authenticated />
element does not show unless the page is refreshed. Likewise, upon logout
, the BaseSideNavigationMenu
element remains visible until the page is refreshed.
How can vue-browser-acl’s directive be made to react on state changes?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:12 (6 by maintainers)
Top Results From Across the Web
State and Lifecycle - React
This page introduces the concept of state and lifecycle in a React component. You can find a detailed component API reference here.
Read more >React setState usage and gotchas - ITNEXT
setState() enqueues changes to the component state and tells React that this component and its children need to be re-rendered with the updated...
Read more >Angular Directives Mapped to React - Dave Ceddia
In Angular, you can respond to changes in an input with ng-change . In React, you can do the same with the onChange...
Read more >What is the React equivalent of an Angular directive that only ...
5 Answers 5 · While I agree with you on "To do it in React you would have to create a special link...
Read more >Creating AngularJS-Inspired "Directive" Components In ReactJS
In AngularJS, the separation of concerns is very clear. Your controllers deal with state and state change while your directives deal with ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, it is reactive with the
v-if
wrapping.This works reactively as expected. Can the
v-role
syntax not be reliably used reactively?