useLoading.ts 502 B

123456789101112131415161718192021
  1. import { ref, ComputedRef, unref, computed, watch } from 'vue'
  2. import { 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(() => unref(loadingRef))
  12. function setLoading(loading: boolean) {
  13. loadingRef.value = loading
  14. }
  15. return { getLoading, setLoading }
  16. }