Newer
Older
Nanping_sponge_GCGL / src / hooks / usePagination.js
@liyingjing liyingjing on 25 Oct 2023 635 bytes 海绵工程管理
import { ref } from 'vue'

export default function usePagination(fetch, params) {
  const pageNum = ref(1)
  const pageSize = ref(10)
  const tableData = ref([])
  const total = ref(0)
  const loading = ref(false)
  const getTableList = async () => {
    loading.value = true
    const res = await fetch({
      ...params.value,
      pageNum: pageNum.value,
      pageSize: pageSize.value
    })
    loading.value = false
    if(res?.code === 200){
      tableData.value = res?.data || []
      total.value = res?.total || 0
    }
  }
  return {
    pageNum,
    pageSize,
    tableData,
    total,
    loading,
    getTableList
  }
}