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

139
Views
Toggle v-if variable inside created() lifecycle method in VUE 3 framework

I have a component, where there are 3 buttons. 2 are visible initially

<template>
  <button v-show="!showLogout" @click="login('google', 'profile, email')">
    Google
  </button>

  <button v-show="!showLogout" @click="login('facebook', 'email')">
    Facebook
  </button>

  <button v-show="showLogout" @click="logout()">
    Log out
  </button>

</template>.

Then I have an data variable inside data()

data() {
return {
  showLogout: false
}

In setup I bring in the HelloJS and in created() I add a listener where I toggle the variable

 setup() {
    return { hello }
  },



 created() {
    hello.on('auth.login', function(auth) {
      this.showLogout = true
    })
  }

But it's not rerendering the buttons (hiding google and facebook and showing logout).

How to get it to work like this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just use the setup hook to define your data properties like :

import {ref} from "vue"
...
 setup() {
     const showLogout= ref(false)
   
     hello.on('auth.login', function(auth) {
       showLogout.value = true
    })

    return { showLogout}
  },
about 4 years ago · Juan Pablo Isaza Report
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!