A
A
Alianos2021-04-23 20:49:44
Vue.js
Alianos, 2021-04-23 20:49:44

Is addEventListener ("@keyup.enter", {alert("enter")}) possible?

Hello, can you please tell me if I can put an enter release listener in the directive using something like el.addEventListener ("@keyup.enter", {alert("enter")})?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2021-04-23
@Alianos

<div id="app">
  <textarea v-test>текст</textarea>
</div>

Vue.directive('test', {
  bind (el) {
    el.addEventListener('keyup', (e) => {
      if (e.keyCode !== 13) {
        return;
      }
      // Нажат Enter и клавиша отпущена
      console.log(e);
    });
  }
});

new Vue({
  el: "#app",
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question