Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Vue.js, how to disable caching of computed properties?

Before 0.12.8, computed properties behave just like getters - every time you access it, the getter function is re-evaluated. In 0.12.8 this has been improved - computed properties are cached and lazily re-evaluated only when necessary.

For my current project, I actually need some properties to be re-evaluated on every access. The reason the current lazy evaluation isn't working is because in some of my properties there are other "dynamic variables" that are not under Vue.js's watch.

like image 379
Dave Avatar asked Aug 19 '15 21:08

Dave


1 Answers

According to the docs, you can simply set cache to false:

computed: {
  example: {
    cache: false,
    get: function () {
      return Date.now() + this.msg
    }
  }
}
like image 182
Xethron Avatar answered Sep 21 '22 23:09

Xethron