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

174
Views
cambiar la variable de datos cuando se pasa a un método en vue

Tengo el siguiente componente vue donde estoy cambiando la clase de la fila principal en función de si una entrada está enfocada o no

 <template> <div class="form form--login"> <div class="form__row" :class="{entered: emailEntered}"> <label class="form__label" for="login-form-email">Email address</label> <input type="text" class="form__control form__control--textbox" name="email-address" id="login-form-email" @focus="emailEntered = true" @blur="handleBlur($event, emailEntered)"> </div> <div class="form__row" :class="{entered: passwordEntered}"> <label class="form__label" for="login-form-password">Password</label> <input type="password" class="form__control form__control--textbox form__control--password" name="password" id="login-form-password" @focus="passwordEntered = true" @blur="handleBlur($event, passwordEntered)"> </div> </div> </template> <script> export default { name: 'login-form', data() { return { emailEntered: false, passwordEntered: false, } }, methods: { handleBlur(e, enteredBool) { if (e.currentTarget.value.trim() === '') { // this doesn't do anything - I can do an if else statement to change this.passwordEntered or this.emailEntered based on the name of the current target, but how do I change the value by passing it into the method? enteredBool = false; } }, } } </script>

pero no parece cambiar la variable que se pasa al método. ¿Cómo paso una variable de datos al método y cambio su valor? ¿O debería hacerlo de otra manera? Realmente no quiero estar haciendo una declaración if else ya que puedo tener un formulario que tiene muchas más entradas y creo que sería realmente ineficiente de mantener

También pensé que podría hacer algo en @bur como puedes hacer @blur="passwordEntered = false" , pero no estaba seguro de cómo verificar si el campo estaba vacío o no.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Para cambiar la variable, debe referirla usando this

 handleBlur(e, enteredBool) { if (e.currentTarget.value.trim() === '') { this[enteredBool] = false; //Change added } },

y la forma en que lo pasas debería ser como

 @blur="handleBlur($event, 'emailEntered')" //Added single quotes

y

 @blur="handleBlur($event, 'passwordEntered')" //Added single quotes
over 4 years ago · Santiago Trujillo 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!