Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
Vue: How to use 'mapState' in mounted in a Vue

Ultimately, I want to call a value(userSso) of db and apply it to change v-if action 'earlier' before people can click.

So I wanted to use mounted hook but it didn't work. If I use functions at computed, then it was too slow that I could click "Account" even userSso is 1. What will be the better way?

components/Lnb.vue

<template>
  <ul>
    <li :class="{ active: navbarState == 7 ? true : false }">
      <a href="/dashboard/settings">
        <img src="../assets/images/ico_settings.svg" alt="icon" /> Settings
      </a>
    </li>
    <li v-if="userSso == 0" :class="{ active: navbarState == 8 ? true : false }">
      <a href="/dashboard/user">
        <img src="../assets/images/ico_user.svg" alt="icon" />
        Account
      </a>
    </li>
  </ul>
</template>
<script>
import { mapState } from 'vuex'
export default {
  name: 'Navbar',

  // props: ['userSso'],
  data() {
    return {
      visible: false,
      opened: false,
      navState: 0,
      itemcount: 0,
    }
  },
  computed: {
    ...mapState('store', {
      navbarState: (state) => state.navbarState,
      backColor: (state) => state.backColor,
      fontColor: (state) => state.fontColor,
      primaryColor: (state) => state.primaryColor,
      //pageSso: (state) => state.pageSso,
      //userSso: (state) => state.userSso,
    }),
  },
  mounted(){
    mapState('store', {
      userSso: (state) => {
        state.userSso
    }
    })
    console.log("mounted mapState userSso => ", userSso)

    
  },
  methods: {
  },
}
</script>

/store/store.js

export const state = () => ({
  userSso: 0,
})

...
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!