addNewTask consolelogthisinput this$netposttaskaddTask context thisinput thenresp = ifrespcode === 200 alert保存成功 else alert保存失败 catcherror =
在addNewTask()函数中,在保存成功的if语句块中,调用fetchTaskList()函数即可。
修改后的代码如下:
addNewTask() { console.log(this.input) this.$net.post('/task/addTask', { context: this.input }).then(resp => { if(resp.code === 200){ alert('保存成功') this.fetchTaskList() } else { alert('保存失败') } }).catch(error => { console.log(error) alert('保存失败') }) },
fetchTaskList() { this.$net.get('task/findAllTask').then(resp => { resp.data.data.records.forEach(item => { if (item.state === 0) { item.state = '未完成' } else { item.state = '已完成' } }) this.taskList = resp.data.data.records }) },
原文地址: https://www.cveoy.top/t/topic/bbyl 著作权归作者所有。请勿转载和采集!