添加一个新行后,我尝试更新表。现在可以添加新行,但我必须刷新页面才能看到新行。同样的问题我有更新/删除方法,但我会在之后找到方法。
getCustomers() {
let url = `/customers`;
const p = axios
.get(url);
return 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;
});
})
.catch(e => {
console.log(e);
});
}
data() {
return {
items: [],
....
....
}
}
<b-table
show-empty
stacked="md"
:items="getCustomers"
:fields="fields"
:current-page="currentPage"
:per-page="perPage"
:filter="filter"
>
这适用于更新
this.$nextTick(() => {
for(let item of this.items){
if(parseInt(item.id) === parseInt(id)) {
item.customer_name = response.data.customer_name;
this.resetModal();
}
}
});