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

82
Views
La información sobre herramientas personalizada con Vue actúa de manera extraña después de hacer clic en el botón dos o tres veces

Creé ese código para desarrollar una información sobre herramientas personalizada que se cierra automáticamente después de 2 segundos desde que el usuario hace clic en un botón. Quiero que funcione solo al hacer clic, no al pasar el mouse.

Funciona bien las dos primeras veces, pero luego actúa de forma extraña cuando vuelvo a hacer clic en él.

Puedes comprobarlo aquí

 <template> <div id="app"> <button @click="copyThat" class="relative-button"> copy that <div class="tooltip" v-if="copied"> copied </div> </button> </div> </template> <script> export default { data(){ return{ copied: false } }, methods: { copyThat: function (){ this.copied = true; setInterval( () => { this.copied = false; }, 2000 ) } } } </script> <style> #app { font-family: Avenir, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } .relative-button{ position: relative; } .tooltip{ position: absolute; top: 130%; padding: 1rem; left: -50%; background: rgba(0,0,0,0.5); color: white; font-weight: bold; z-index: 100; width: 113px; height: 30px; border-radius: 4px; padding: 7px; text-transform: capitalize; font-weight: 400; font-size: 13px; } </style>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

El problema es que no borra el interval que creó, por lo que una vez que haga clic en el botón Copiar, se creará un interval nuevo y se ejecutarán varios intervalos cada 2 segundos, lo que hará que su barra de herramientas se vuelva muy extraña.

Puede usar setTimeout o window.clearInterval para borrar todo el intervalo antes de crear uno nuevo.

about 4 years ago · Juan Pablo Isaza Report

0

Use setTimeout en su lugar:

 copyThat: function() { this.copied = true; setTimeout(() => { this.copied = false; }, 2000); }
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!