hcong
2024-09-27 5aa63351c15fde21178f0c962570df65eba38560
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// 分页逻辑管理
import { ref, watch } from 'vue';
import { useEvent } from './event';
 
/**
 * 分页监听逻辑
 * 1. 监听页码和单页数据量变换
 * 2. 可添加响应触发事件
 */
export function usePagination() {
  const { invokeEvent, addEvent: addPageEvent } = useEvent();
  const currentPage = ref(1);
  const pageSize = ref(20);
  watch(currentPage, (nValue, oValue) => {
    if (nValue != oValue) {
      invokeEvent();
    }
  });
  watch(pageSize, (nValue, oValue) => {
    if (nValue != oValue) {
      invokeEvent();
    }
  });
 
  return { currentPage, pageSize, addPageEvent };
}