vue.js logo

Custom Directives for DOM Manipulations


Vue allows you to create custom directives, which are particularly useful for direct DOM manipulations. This can be a powerful feature for integrating third-party libraries, managing focus, or applying touch interactions.


<template>
        <input v-focus/>
      </template>

      <script>
      export default {
        directives: {
          focus: {
            // Directive definition
            mounted(el) {
              el.focus(); // Focus the element when it is inserted into the DOM
            }
          }
        }
      }
      </script>