index.ts 763 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { unref, watch } from 'vue'
  2. import { debugWarn } from '@element-plus/utils'
  3. import type { MaybeRef } from '@vueuse/core'
  4. type DeprecationParam = {
  5. from: string
  6. replacement: string
  7. scope: string
  8. version: string
  9. ref: string
  10. type?: 'API' | 'Attribute' | 'Event' | 'Slot'
  11. }
  12. export const useDeprecated = (
  13. { from, replacement, scope, version, ref, type = 'API' }: DeprecationParam,
  14. condition: MaybeRef<boolean>
  15. ) => {
  16. watch(
  17. () => unref(condition),
  18. (val) => {
  19. if (val) {
  20. debugWarn(
  21. scope,
  22. `[${type}] ${from} is about to be deprecated in version ${version}, please use ${replacement} instead.
  23. For more detail, please visit: ${ref}
  24. `
  25. )
  26. }
  27. },
  28. {
  29. immediate: true,
  30. }
  31. )
  32. }