element-plus+vue3+ts Pagination分页 删除最后一条数据返回上一页问题

一定记住对后端的请求是在加载函数之后的,我这里如果把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;//需要后台返回的总条数
    })
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,让我们开始吧! 首先,我们需要在项目中安装 `element-plus`,你可以使用 npm 或 yarn 进行安装,比如: ``` npm install element-plus --save ``` 或者 ``` yarn add element-plus ``` 安装完成后,我们需要在 `main.ts` 中引入并使用 `element-plus`,代码如下: ```typescript import { createApp } from 'vue' import ElementPlus from 'element-plus' import 'element-plus/lib/theme-chalk/index.css' import App from './App.vue' const app = createApp(App) app.use(ElementPlus) app.mount('#app') ``` 现在我们已经成功引入了 `element-plus`,接下来我们可以开始编写一些组件。 例如,在 `src/components` 目录下创建一个名为 `HelloWorld.vue` 的组件,代码如下: ```vue <template> <div class="hello"> <el-button type="primary" @click="handleClick">Click me!</el-button> </div> </template> <script lang="ts"> import { defineComponent } from 'vue' import { ElButton } from 'element-plus' export default defineComponent({ name: 'HelloWorld', components: { ElButton }, methods: { handleClick() { console.log('Hello, world!') } } }) </script> ``` 在这个组件中,我们使用了 `ElButton` 组件,并在它的点击事件中打印了一条消息。 接下来,我们可以在 `App.vue` 中使用这个组件,代码如下: ```vue <template> <div id="app"> <HelloWorld /> </div> </template> <script lang="ts"> import { defineComponent } from 'vue' import HelloWorld from './components/HelloWorld.vue' export default defineComponent({ name: 'App', components: { HelloWorld } }) </script> ``` 现在,我们已经成功使用 `element-plus` 来创建了一个简单的组件,并在 `App.vue` 中使用它。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值