I am trying to leverage Vue's computed property to detect changes in multiple pieces of data and automatically execute a function. However, I only want to use computed as a function without generating any new values.
It seems that computed properties do not get executed automatically unless they are used directly. To work around this, I have decided to return null from the computed function and then call it using {{}} in the template tag. Is this the correct approach? I am trying to avoid using watch whenever possible.
Additionally, I am wondering if it is possible to define a process in my "afterRendering" method which does not return anything, and then force it to be called using {{afterRendering}} after each render.
<template>
...
{{afterRendering()}} <!--this will run after every render.-->
{{MyComputed}} <!--this will run when there are changes in dependent bindings.-->
</template>
...
export default {
methods: {
afterRendering: function () {
// Define the process here
},
},
computed: {
MyComputed: function () {
if (!!Achanged || !!Bchanged) {
// Check for changes in A and B here
return null
}
},
},
}