useShow.ts 610 B

1234567891011121314151617181920212223242526
  1. import http from '/admin/support/http'
  2. import { Ref, ref } from 'vue'
  3. import { isFunction } from '../../support/helper'
  4. export function useShow(path: string, id: string | number, fillData: null | Ref = null) {
  5. const loading = ref<boolean>(true)
  6. const data = ref<object>()
  7. // 后置钩子
  8. const afterShow = ref()
  9. http.get(path + '/' + id).then(r => {
  10. loading.value = false
  11. data.value = r.data.data
  12. if (fillData) {
  13. fillData.value = r.data.data
  14. if (isFunction(afterShow.value)) {
  15. afterShow.value(fillData)
  16. }
  17. }
  18. })
  19. return { data, loading, afterShow }
  20. }