How vuejs knows the depenedencies of computed property for caching?

前端 未结 3 1427
猫巷女王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:46

    From the docs it reads that: Computed properties are cached, and only re-computed on reactive dependency changes. However the following fiddle shows something a bit different.

    1. https://jsfiddle.net/z11fe07p/267/

    From the fiddle if you set the flag to 2, the computed property will be re-evaluated and executed if you change myOtherValue, however this will not happen if the flag is set to 1. I think it keeps track of your if conditions.

    In the docs usually you can find links to the relevant source code. Here is the code for computed properties:

    • https://github.com/search?utf8=%E2%9C%93&q=repo%3Avuejs%2Fvue+extension%3Ajs+%22computed%22&type=Code

提交回复
热议问题