Issue
I find myself in a situation where I must temporarily hold the output of a function call in Vue templates. This is a common scenario within loops, especially when computed properties are not easily applicable.
<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 code snippet:
getVehicleTypeData: function(vehicleType){
let options = _.find(this.vehicleTypeOptions, (obj)=>{
return obj.vehicleType==vehicleType;
});
return options;
}
In order to optimize performance, I am in need of a variable to cache the result of the function call.
What would be the most suitable Vue approach to address this issue?