view.py
def delete_student(request):
data = json.loads(request.body.decode("utf-8"))
try:
obj_student = Student.objects.get(sno = data['sno'])
obj_student.delete()
students = list(Student.objects.all().values())
return JsonResponse({'code': 1, 'data': students})
except Exception as e:
return JsonResponse({'code': 0, 'msg': "数据库删除异常" + str(e)})
StudentInfo.vue
//删除按钮
deleteStudent(row){
this.$confirm('是否确认删除', '提示', {confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'})
.then(() => {
let _this = this
axios
.post(_this.baseURL + 'student/delete/', {sno: row.sno})
.then(res => {
if(res.data.code === 1){
_this.students = res.data.data;
_this.total = res.data.data.length;
_this.getPageStudents();
_this.$message({
message: "删除数据成功",
type: 'success'
})
}else{
_this.$message.error(res.data.msg)
}
})
})
.catch(() => {
this.$message({
type: 'info',
message: "取消删除"
})
})
}