一定记住对后端的请求是在加载函数之后的,我这里如果把load()放在外面会导致先执行load()再向后端请求post,即使你查到当前页值改变了,在向后端请求的时候也还是原来的页数,删除最后一条数据的时候就会报错。
const handleDelet = (id) => { //删除
request.post("/staffs/classify/" + currentPage.value + "/" + pageSize.value, aa).then(res =>{
if(res.data.account==1){
currentPage.value=currentPage.value-1;
}
currentPage.value = currentPage.value < 1 ? 1 : currentPage.value;
})
request.delete("/staffs/" + id).then(res => {
load();//调用load要放在then里面,否则会先执行load函数
})
// load();//在这里调用会导致先执行load()再向后端请求post,删除最后一条数据返回上一页时就会出现当前页currentPage并没更新而报错
}
const load = () => { //获取并更新页面人员信息
request.post("/staffs/classify/" + currentPage.value + "/" + pageSize.value, aa).then(res => {
// console.log(currentPage.value);
console.log(res);
tableData.arr=res.data.data;
total.value=res.data.allAccount;//需要后台返回的总条数
})
}