How vuejs knows the depenedencies of computed property for caching?

前端 未结 3 1376
猫巷女王i
猫巷女王i 2021-02-01 16:21

I have this Vue.js code:

new Vue({
  data:{
         myValue:\'x\',
         myOtherValue:\'y\'
  },
  computed: {
       myComputed: myFunction(){
          ret         


        
3条回答
  •  醉梦人生
    2021-02-01 16:51

    It's the reactivity system of Vue.js, not a caching system.

    The data in a component will be convert to getters and setters. When you access a value via a getter, the getter will add it to the dependencies, and when you modify the value via a setter, the setter will notify everyone who depends on the value.

    Here is the source code, all the magic happens in this function: https://github.com/vuejs/vue/blob/dev/src/core/observer/index.js#L131

提交回复
热议问题