I have a totals calculation of certain values in a pagination. This calculation is in a computed property inserted in a component. The problem I have with another similar component that needs to use the same computed property >. Here is part of the code below for the totals calculation only (if you wish I can post the component completely):
// ... dentro de methods
vlr (param) {
let today = new Date()
today.setHours(0, 0, 0, 0)
let venc = new Date(param.ven)
venc.setHours(0, 0, 0, 0)
if (venc.getTime() >= today.getTime()) {
return parseFloat(param.total)
}
return param * 0.02
}
},
computed: {
getTotal (param) {
let total = {}
if (param.length) {
param.forEach(idx => {
idx.vlr = this.vlr(idx)
Object.keys(idx).forEach(key => {
if (!total[key]) {
total[key] = {
counter: 0,
sum: 0,
values: [],
uniqueCounter: 0
}
}
total[key].counter += 1
total[key].sum += idx[key]
if (total[key].values.indexOf(idx[key]) === -1) {
total[key].uniqueCounter += 1
total[key].values.push(idx[key])
}
})
})
}
return total
}
}
My question is exactly this one. How to efficiently reuse a computed property ?
I tried using mixins , but I was not successful so far for this situation.
Note: The code was done with ESLint.