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

971
Views
VueJS agrega condicionalmente un atributo para un elemento

En VueJS podemos agregar o eliminar un elemento DOM usando v-if:

 <button v-if="isRequired">Important Button</button>

pero, ¿hay alguna manera de agregar/eliminar atributos de un elemento dom, por ejemplo, para lo siguiente, establezca condicionalmente el atributo requerido:

 Username: <input type="text" name="username" required>

por algo similar a:

 Username: <input type="text" name="username" v-if="name.required" required>

¿Algunas ideas?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Tratar:

 <input :required="test ? true : false">

Actualización: ha cambiado en Vue 3, vea esta respuesta https://stackoverflow.com/a/64598898

over 4 years ago · Santiago Trujillo Report

0

La forma mas simple:

 <input :required="test"> // if true <input :required="!test"> // if false <input :required="!!test"> // test ? true : false
over 4 years ago · Santiago Trujillo Report

0

La representación condicional de los atributos cambió en Vue 3. Para omitir un atributo, use null o undefined .

Vista 2:

 <div :attr="false"> Result: <div> <div :attr="null"> Result: <div>

Vista 3:

 <div :attr="false"> Result: <div attr="false"> <div :attr="null"> Result: <div>
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!