1 回答
TA贡献1890条经验 获得超9个赞
我认为您在输入数据后错过了再次获取数据。所以你可以这样做:
<script>
export default {
data() {
return {
success: false,
task: {},
tasks: [],
errors: []
};
},
created() {
this.fetchTasks()
},
methods: {
fetchTasks() {
let uri = `/api/tasks`;
this.axios.get(uri).then(response => {
this.tasks = response.data.data;
});
},
addTask() {
let uri = `/api/tasks`;
this.axios
.post(uri, this.task)
.then(response => {
this.success = response.data.success;
this.fetchTasks() // you need to call your api again, here, to fetch the latest results after successfully adding a new task
})
.catch(error => {
if (error.response.status == 422) {
this.errors = error.response.data.errors;
}
});
},
error(field) {
return _.head(field);
},
deleteTask(id) {
let uri = `/api/tasks/${id}`;
this.axios.delete(uri).then(response => {
this.success = response.data.success;
});
}
}
};
</script>
- 1 回答
- 0 关注
- 158 浏览
添加回答
举报