vue directive parameter

<template>
  <div>
    <p v-customDirective:arg1.modifier1="value">This is a paragraph.</p>
  </div>
</template>

<script>
export default {
  directives: {
    customDirective: {
      bind(el, binding) {
        // Called only once, when the directive is first bound to the element
      },
      inserted(el, binding) {
        // Called when the bound element has been inserted into its parent node
      },
      update(el, binding) {
        // Called whenever the component is updated
      },
      componentUpdated(el, binding) {
        // Called after the component and its children have been updated
      },
      unbind(el, binding) {
        // Called only once, when the directive is unbound from the element
      }
    }
  }
}
</script>
  • In the template section, a paragraph element is defined with a custom directive v-customDirective and its parameters: arg1 as the argument and modifier1 as the modifier. The value attribute is set to "value."

  • In the script section, a custom directive named customDirective is registered within the directives option of the Vue component.

  • The directive object has five lifecycle hooks: bind, inserted, update, componentUpdated, and unbind.

  • The bind hook is called once when the directive is first bound to the element.

  • The inserted hook is called when the bound element has been inserted into its parent node.

  • The update hook is called whenever the component is updated, but it does not guarantee that the children have been updated.

  • The componentUpdated hook is called after the component and its children have been updated.

  • The unbind hook is called once when the directive is unbound from the element.