I create a array which contains objects describing information of buttons. In my template I have a class active which is represent the active button. By default the first button of the array is active.
template:
<b-button-group class="page-buttons mt-2" size="sm">
<b-button v-for="btn in buttons"
:key="btn.key"
@click="selectPage(btn.key)"
v-bind:class="{'active': btn.active}">{{ btn.caption }}
</b-button>
</b-button-group>
Script:
methods: {
$createPaginationButtons: function(numberParameters) {
const numberPages = Math.ceil(numberParameters / NUMBER_ELEMENT_PER_PAGE);
this.buttons = [];
for (let i = 0; i < numberPages; i++) {
this.buttons.push({
caption: `PAGE ${i + 1}`,
active: (i === 0),
key: (i + 1)
});
}
Vue.set(this.buttons[0], 'active', true);
}
}
The buttons array is initialize in data as an empty array.
when my buttons array changes, the view is updated and display the correct number of buttons but my class active is not triggered.
Have you any idea.
dataobject?, also when or what triggerscreatePaginationButtons?