我有一个在 Vue 和 Axios 上制作的包含 2 个选项卡(问题和数据)的页面。 在第一个选项卡中,我填写表单并提交 - 保存按钮 v-on:click="save"。
save: function() {
axios({
method: 'patch',
url: url,
data: this.data
})
.then(function (response) {
this.data = response.data;
}
在第二个选项卡(数据)中,我有已保存数据的列表:
mounted() {
axios
.get('/api/recommended-products/?patient_uuid=' + '{{patient.uuid}}')
.then(response => (this.data= response.data.results))
}
现在,当我更改“问题”选项卡中的答案时,“数据”选项卡中的列表应该自动更改。如果我刷新页面,它就会改变 - Mounted() 有效。 我尝试创建 updateList() 函数:
updateList: function() {
axios
.get('/api/recommended-products/?patient_uuid=' + '{{patient.uuid}}')
.then(response => (this.data= response.data.results))
}
并将其添加到 save() 函数中,例如:
save: function() {
axios({
method: 'patch',
url: url,
data: this.data
})
.then(function (response) {
this.data = response.data;
this.updateList();
}
问题是这种方式第二次可以工作(有时有效有时不行)。所以我只是将 location.reload(); 添加到 save() 但我不喜欢这种方法。是否可以在不刷新页面的情况下更新数据列表?我对 updateList() 函数做错了什么?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号