Search code examples
javascriptvue.jscomponentsapplication-lifecyclecomputed-properties

Vue.js updated hook for counting


On the user's sidebar there is a number of new unseen notifications. This number is generated by a function which counts all new notifications with the flag viewed: false from API.

My question is: what will be good practice if I want to place this function in one of the lifecycle hooks inside the component of the sidebar? updated() or computed?


Solution

  • You should be using computed if you - as it seems - want the component to change whenever the computed value changes.