Problem
I have the need to temporarily store the results of a method call in Vue templates. This is particularly common inside loops, where I cannot easily use computed properties.
<ul>
<li v-for=vehicleType in vehicleTypes :key=vehicleType>
<h3>{{ vehicleType }}</h3>
<div v-if=getVehicleTypeData(vehicleType)>
{{ getVehicleTypeData(vehicleType).costPerMile }}<br>
{{ getVehicleTypeData(vehicleType).costPerHour }}<br>
</div>
</li>
</ul>
Javascript snippet:
getVehicleTypeData: function(vehicleType){
let options = _.find(this.vehicleTypeOptions, (obj)=>{
return obj.vehicleType==vehicleType;
});
return options;
}
To improve performance, I really need a variable to store the method call result.
What is the Vue way to solve this problem?