优化删除的操作 ----分页器
// 根据 id 删除文章
async remove(id) {
const confirmResult = await this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
// 确认删除
// 2. 发起请求
const { data: res } = await this.$http.delete('/my/article/info', {
params: { id }
})
if (res.code === 0) {
// 删除成功
this.$message.success(res.message)
+ // 当前页只有1条数据 && 当前的页码值>1
+ // 则说明当前页已没有数据可显示,需要让页码值 -1
+ if (this.artList.length === 1 && this.q.pagenum > 1) {
+ this.q.pagenum--
+ }
// 刷新列表数据
this.getArtList()
} else {
// 删除失败
this.$message.error(res.message)
}
}).catch(err => {
// 取消删除
console.log(err)
})
}