【发布时间】:2019-09-25 09:37:40
【问题描述】:
我在 Vuetify 中有一个数据表,它通过 REST 获取请求填充,使用的是在安装应用程序时调用的函数“getData”。表中的<td> 具有用户可以点击以“锁定”期间(行/列交叉点)的按钮。
当他们点击按钮时,他们会弹出一个确认对话框。当他们点击“OK”时,会调用一个保存方法,通过 REST PATCH 请求将当前日期写回数据库(见下文)。
我的问题是,网格没有根据补丁请求的结果进行更新。我必须手动刷新页面才能看到结果。这里的常见模式是什么?我应该通过getData 再次拉下数据以刷新表格吗?我应该直接更新数据表所在的数组吗?
getData 方法:
getData() {
var self = this;
return axios
.get("http://127.0.0.1:5000/api/estimatefinal/periods?dataset=capital")
.then(function(response) {
self.periods = response.data;
})
.catch(function(error) {
alert(error);
});
},
保存方法:
save(item) {
var self = this;
axios
.patch("http://localhost:5000/api/estimatefinal/period/" + self.id, {
date: moment(self.selected_date, "YYYY-MM-DD").format(
"YYYY-MM-DDTH:m:s"
)
})
.then(function() {
this.getData(); // ????
})
.catch(function(error) {
alert(error)
});
this.getData(); // ????
this.close();
}
【问题讨论】:
标签: vue.js datatable axios refresh vuetify.js