[Vuejs]-How to manage re-rendering a navigation on a SPA in vue js

1👍

You need to set the user authentication status globally. Vuex can be used for this purpose.

Example code

const state = {
  isAuth: false
}

const mutations ={
  setAuth:(state,value)=>state.isAuth = value
}

const actions = {
  loginRequest:function({commit}){
    // perform login request
    commit('setAuth',true); // call this after you get the login response
  }
}

Inside the component add a computed function

computed:{
  isAuth:function(){
    return this.$store.state.isAuth;
  }
}

Now isAuth can use for handling the condition to hide the sections you need.

👤Rijosh

Leave a comment