0

I created a login page, where I made the conditions. if not logged in displays NAVBAR A if login is successful displays NAVBAR B. In the login process I created a local storgare storage in which a token is stored. I ask why is mounted late rendering? when the user is logged in it should render navbar B, it works if it is refreshed first

my code app.vue

<v-main>
     <NavA v-if="token==='' "/> //if not login
     <NavB v-if="token!='' "/> // if login success
      <router-view />
</v-main>

data: () => ({
    drawer: true,
    token: '',
  }),

  mounted () {
      this.token = localStorage.getItem('token')
  },
1
  • give token: null and <NavA v-if="token == null "/> Commented Jan 4, 2021 at 5:52

3 Answers 3

1

change "mounted" to "created", maybe it helps.

Sign up to request clarification or add additional context in comments.

Comments

0

You should always use if-else condition.

<v-main>
   <NavA v-if="token == null "/> //if not login
   <NavB v-else /> // else login success
   <router-view />
</v-main>

data: () => ({
  drawer: true,
  token: null,
}),

mounted () {
   this.token = localStorage.getItem('token')
},

This is working for me. See in Sandbox.

https://codesandbox.io/s/charming-aryabhata-pl2k4?file=/src/App.vue

1 Comment

For this it works, but when the rendering doesn't work, it must be refreshed first
0

You can try using beforeMount hook instead of using the mounted hook.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.