I can't get how to properly use computed properties when displaying data organized as columns with table. The full example of my code is available at jsfiddle, here is the short version and description. I want to render this data as a table:
var vueData = {
objects: [
{
name: "objectName",
objectData: [
{prop1: "val1", prop2: "val2"}
]
}
]
}
In this vueData
each element of objectData
array should be displayed as a column (that column represents data of one month or day). The props in objectData
's elements should be displayed not as is, but as computed values. And that displayed values should reflect changes of vueData
.
So I came to this vue template:
<table>
<tr>
<th>Object Name</th>
<th>Data Piece 1</th>
<th>Data Piece 2</th>
</tr>
<template v-for="obj in objects">
<tr>
<th rowspan="2">{{ obj.name }}</th>
<td v-for="dataPiece in obj.objectData">{{ compute(dataPiece.prop1) }}</td>
</tr>
<tr><td v-for="dataPiece in obj.objectData">{{ compute(dataPiece.prop2) }}</td></tr>
</template>
</table>
All works fine except that I have used methods, not vue's computed properties. The problem with methods is that their results do not cache and after a single prop change ALL cells' values are recomputed.
I could use a vue component for each cell with computed property instead of td
s , but it looks like overkill, as table can be big.
Is there any another solution from the vue's point of view? (I mean without changing the data structire or appearance of the table, etc).
compute
function. – Roy J