0
I find a way to re-render data from table.
Add v-if=”renderComponent” to < b-table >
data() {
return {
renderComponent: true,
};
},
Create a new method:
forceRerender() {
this.renderComponent = false;
this.$nextTick(() => {
this.renderComponent = true;
});
}
And I use forceRerender(); after my event, and it works.
0
Please see my comments in code below:
getCustomers() {
let url = `/customers`;
const p = axios
.get(url);
this.customers = p.then(response => {
const i = response.data.data;
return i || [];
});
},
addCustomer() {
let newCustomer = {
customer_name: this.customer_name
};
axios
.post("/customers", newCustomer)
.then(response => {
this.items = response.data;
this.$nextTick(() => {
this.$refs.modal.hide();
this.items.customer_name = response.data.customer_name;
this.customers.push(response.data) // something like this can help
});
})
.catch(e => {
console.log(e);
});
}
data() {
return {
items: [],
customers: [] // add this to make reactive
}
}
mounted() {
this.getCustomers(); // run the function when page/component mounted
}
<b-table
show-empty
stacked="md"
:items="customers"
:fields="fields"
:current-page="currentPage"
:per-page="perPage"
:filter="filter"
>
Source:stackexchange.com