mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-15 22:06:45 +08:00
新增教师节
This commit is contained in:
46
src/hooks/useRequest.js
Normal file
46
src/hooks/useRequest.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import { isRef, reactive, ref, toRefs, unref, watch, watchEffect } from "vue";
|
||||
import http from '@/api/configPublic'
|
||||
|
||||
const useTotalPage = (_url, params, config = {}) => {
|
||||
const s = _url.split(" ");
|
||||
const url = s[0];
|
||||
let methods = 'post'
|
||||
if (s[1]) methods = 'get'
|
||||
const state = reactive({
|
||||
data: [],
|
||||
total: 1,
|
||||
current: 1,
|
||||
pages: 1,
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
loading: false
|
||||
});
|
||||
|
||||
if (isRef(_url)) {
|
||||
watchEffect(fetch);
|
||||
}
|
||||
|
||||
function reset() {
|
||||
state.data = [];
|
||||
state.loading = false;
|
||||
}
|
||||
|
||||
function fetch() {
|
||||
state.loading = true;
|
||||
return http[methods](unref(url), !s[1] ? unref(params) : { params: unref(params) }, { ...config }).then(r => {
|
||||
state.data = r.data?.records || 0;
|
||||
state.total = r.data?.total || 0;
|
||||
state.loading = false;
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
fetch,
|
||||
reset,
|
||||
};
|
||||
}
|
||||
|
||||
export {
|
||||
useTotalPage
|
||||
}
|
||||
Reference in New Issue
Block a user