StudentInfo.vue
//编辑按钮显示修改表单
updateStudent(row){
this.isEdit = true;
this.dialogVisible = true;
this.studentForm = JSON.parse(JSON.stringify(row));
},
//信息更新函数
submitUpdateStudent() {
let _this = this;
axios
.post(_this.baseURL + 'student/update/', _this.studentForm)
.then(res => {
if (res.data.code === 1) {
//获取students数据
_this.students = res.data.data;
//获取students[]数据长度
_this.total = res.data.data.length;
//更新pageStudents[]
_this.getPageStudents();
//打印信息
_this.$message({
message: "数据更新成功",
type: "success",
})
} else {
_this.$message.error(res.data.msg);
}
})
.catch(err => {
_this.$message.error("后端数据查询异常");
})
},
view.py
def update_student(request):
data = json.loads(request.body.decode("utf-8"))
try:
# 保存数据
obj_student = Student.objects.get(sno=data['sno'], name=data["name"])
obj_student.mobile = data["mobile"]
obj_student.email = data["email"]
obj_student.address = data["address"]
obj_student.save()
# 返回Student表
students = list(Student.objects.all().values())
return JsonResponse({'code': 1, 'data': students})
except Exception as e:
return JsonResponse({'code': 0, 'msg': "数据库修改异常" + str(e)})