veritas
veritas

Reputation: 35

vue js increase the value with mousedown

With this code, the pos_number only increases by one when the mouse is held down. How to make a button that will increase the value as long as the mouse is held down?

<button
  @mousedown="setValue({name: 'robotx_increase',value: (robotx_increase = 'true'),});robotx_pos_number ++ "
  @mouseup="setValue({name: 'robotx_increase',value: (robotx_increase = 'false'),})">
</button>

data() {
    return {
      robotx_pos_number: 0
    }
  },

Upvotes: 0

Views: 318

Answers (1)

Nip van wees
Nip van wees

Reputation: 11

You could call a function like 'startAdding()' on the mousedown event, which uses the setInterval method that keeps adding 1 to 'robotx_pos_number' every x milliseconds. This interval should then be cleared with the mouseup event.

Upvotes: 1

Related Questions