Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
How can I get a mouseup event when the mouse goes up outside of the element with vue?

I can easily capture the mousedown event on the element by adding a @mousedown. If the cursor goes up inside of the element, adding @mouseup will capture the event.

However, if the mouse goes up outside of the element (include outside of the browser window), the mouseup event is not generated.

How can I obtain this event?

new Vue({
  el: '#app',
  
  data: {
    boxvalues: [true, false],
  },
  
  methods: {
    mousedown() {
      console.log( "mousedown" );
    },
    
    mouseup() {
      console.log( "mouseup" );
    }
    

  },
})
.thediv {
  width: 200px;
  height: 200px;
  background-color: red;
  margin: 8px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="app">
  
  <div class="thediv" @mousedown="mousedown" @mouseup="mouseup">
  </div>
    
</div>

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The highest level to track mouse events is on window object.

window.addEventListener('mouseup', function(e) {…}, false);

Mouse events outside browser window can't be tracked due to security reasons. However you might want to use Pointer Lock API to prevent accidental mouse move outside of browser window: https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API

about 4 years ago · Juan Pablo Isaza Relatório

0

You can try with @mouseleave :

new Vue({
  el: '#app',
  
  data: {
    boxvalues: [true, false],
  },
  
  methods: {
    mousedown() {
      console.log( "mousedown" );
    },
    
    mouseup() {
      console.log( "mouseup" );
    }
    

  },
})
.thediv {
  width: 200px;
  height: 200px;
  background-color: red;
  margin: 8px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="app">
  
  <div class="thediv" @mousedown="mousedown" @mouseup="mouseup" @mouseleave="mouseup">
  </div>
    
</div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda