Home  >  Q&A  >  body text

javascript - What is the underlying dependency principle of Vue's calculated properties?

If calculated property

var vm = new Vue({
  data: {
    a: 'hi',
    b:'buu',
    c: 'zzz'
  },
  computed: {
    example: {
      return  this.a + this.b
    }
  }
})

If attributes a and b change, the calculated attributes will change responsively. How is this mechanism implemented?
How to know the changes in a and b inside?

ringa_leeringa_lee2680 days ago737

reply all(2)I'll reply

  • 阿神

    阿神2017-06-17 09:18:34

    Thanks for the invitation.

    I don’t know about VUE, but this change of attribute value is just like the difference between reference and valuein other languages.
    Example:

    Suppose the address referenced by a is 0xaaa0, and the value loaded by 0xaaa0 is 'hi0'
    Change the address referenced by a to 0xaaa1, and the value loaded by 0xaaa1 is 'hi1'
    Then when a is obtained, the value changes.

    reply
    0
  • 漂亮男人

    漂亮男人2017-06-17 09:18:34

    Look at the in-depth response part of the vue documentation

    reply
    0
  • Cancelreply