I have a vue component which contains this table, which also has a component inside its only row:
<template>
<b-table :items="records">
<template slot="row-details">
<child-component/>
</template>
</b-table>
</template>
I'm keeping the data inside the table very simple, for sample purposes:
data() {
return {
records: [{
name: "Parent Row",
_showDetails: true
}]
};
}
The child-component
inside the row is quite simple too:
<template>
<div>
<p>{{number}}</p>
</div>
</template>
<script>
export default {
data() {
return {
number: Math.random(),
isUpdating: console.log("Updating Child Component")
};
},
}
</script>
If I add a new row in the parent table using records.push(newRow)
everything works fine, I can see the new row and, in the child component, number
does not change.
BUT If I add the new row using records.unshift(newRow)
the child component is reloaded, the "Updating child component" message shows and number
changes every time.
Is this the expected behaviour? How can I keep the number
so it does not change when I unshift a new record?
I have created a working sample here.