Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
Unable to change data value in vue

I have a button that toggles the password from **** to text. Since I have multiple of the same buttons, I wanted to use the same method to change the boolean value of the button depending on the argument passed.

<div class="input-wrapper" :class="{'error-field': isInvalidMe('a')}">
  <input :type="asNewPassword ? 'password' : 'text'" v-model="adminNewPassword" class="input-text required" placeholder="New Password" required/>
  <span
    :class="{ 'brand-color': !asNewPassword, 'supportive-color-dark-2': asNewPassword }"
    :style="!asNewPassword ? {'color': primary + ' !important'} : {}"
     @click="togglePassword('asNewPassword')"
  >
     <i class="fa" :class="{'fa-eye-slash': asNewPassword, 'fa-eye': !asnewPassword}"/>
  </span>
</div>
togglePassword: function (typeOfPassword) {
                typeOfPassword = !typeOfPassword
            }
asNewPassword: true,

The togglePassword("asNewPassword") is suppose to change its value from false to true and vice versa but method does not seem to work. I've tried using this.typeOfPassword but it doesn't work for me as well.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You are passing a string as a value to your method and then trying to treat it as a Boolean value. You should define a property in your components local state (data function) and then toggle that; Here's the code:

<div class="input-wrapper" :class="{'error-field': isInvalidMe('a')}">
  <input :type="asNewPassword ? 'password' : 'text'" v-model="adminNewPassword" class="input-text required" placeholder="New Password" required/>
  <span
    :class="{ 'brand-color': !asNewPassword, 'supportive-color-dark-2': asNewPassword }"
    :style="!asNewPassword ? {'color': primary + ' !important'} : {}"
     @click="togglePassword"
  >
     <i class="fa" :class="{'fa-eye-slash': asNewPassword, 'fa-eye': !asnewPassword}"/>
  </span>
</div>
export default {
  data() {
    return {
      asNewPassword: true,
    };
  },
  methods: {
    togglePassword() {
      this.asNewPassword = !this.asNewPassword;
    },
  },
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Replace

@click="togglePassword('asNewPassword')"

With

@click="asNewPassword = !asNewPassword"

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda