tryOnScopeDispose.js 293 B

12345678910111213
  1. import { getCurrentScope, onScopeDispose } from 'vue';
  2. /**
  3. * Call onScopeDispose() if it's inside a effect scope lifecycle, if not, do nothing
  4. *
  5. * @param fn
  6. */
  7. export function tryOnScopeDispose(fn) {
  8. if (getCurrentScope()) {
  9. onScopeDispose(fn);
  10. return true;
  11. }
  12. return false;
  13. }