Vue using custom instructions to bind to multiple dom elements will collectively trigger componentUpdated hooks

<template>
  <div class="entry">
    <input type="text" v-test v-model="a" id="a">
    <input type="text" v-test v-model="b" id="b">
  </div>
</template>

<script>
  export default {
    name: "entry",
    data () {
      return {
        a: 1,
        b: 2
      }
    }
    directives: {
      test: {
        componentUpdated (el) {
          console.log(el)
        }
      }
    }
  }
</script>

code as above, typing in any input box triggers componentUpdated , so the corresponding el is printed twice. The official document also says that the VNode of the component where the componentUpdated: directive is located and its child VNode are all updated and called. , my understanding is: which element is bound to, it is called when the corresponding element and its child elements are updated. Two input are sibling elements, so updating one should not affect the other, or there is something wrong with my understanding. Look at the correction.

Mar.06,2021

the update here is only the update, of the whole component. Although in the end, it only updates an input, but it actually triggers the update function of your entry component


.

encountered the same problem.
changing the value of one of them will trigger all instruction binding dom

how can I tell the difference?

Menu