// 接口数据的获取 import { onActivated, onDeactivated, ref, watch } from 'vue'; export function useFetchData(fetch) { // 分页信息 const currentPage = ref(1); const totalPage = ref(1); const pageSize = ref(20); const total = ref(0); watch(currentPage, (nValue, oValue) => { if (nValue != oValue) { fetchData(); } }); watch(pageSize, (nValue, oValue) => { if (nValue != oValue) { fetchData(); } }); // 加载状态, 0: 加载完成; 1: 加载中; 2: 已全部加载; 3: 加载失败; const loadStatus = ref(0); // 数据获取 function fetchData() { fetch(currentPage, pageSize).then((res) => { }); } }