JSFiddle - React, Tailwind, and code Playground
HTML
<div id="app">
<div>{{myComputed}}</div>
</div>
JavaScript
const flag=1;
var runs=0;
var vm=new Vue({
el:"#app",
data:{
myValue:'x',
myOtherValue:'y'
},
computed: {
myComputed: function(){
runs++;
console.log("This function was called "+runs+" times");
this.changeOtherValue();
if (flag==1){
return this['my' + 'Value']
}
else
return this['my' + 'Other' + 'Value']
}
},
methods:{
changeOtherValue:function(){
var self=this;
setTimeout(function(){
self.myOtherValue='z';
},2000)
}
}
})