useLoading.ts 534 B

1234567891011121314151617181920212223
  1. import { ref, ComputedRef, unref, computed, watch } from 'vue';
  2. import type { BasicTableProps } from '../types/table';
  3. export function useLoading(props: ComputedRef<BasicTableProps>) {
  4. const loadingRef = ref(unref(props).loading);
  5. watch(
  6. () => unref(props).loading,
  7. (loading) => {
  8. loadingRef.value = loading;
  9. }
  10. );
  11. const getLoading = computed(() => {
  12. return unref(loadingRef);
  13. });
  14. function setLoading(loading: boolean) {
  15. loadingRef.value = loading;
  16. }
  17. return { getLoading, setLoading };
  18. }