onMountedOrActivated.ts 290 B

123456789101112131415161718
  1. import { nextTick, onMounted, onActivated } from 'vue';
  2. export function onMountedOrActivated(hook: Fn) {
  3. let mounted: boolean;
  4. onMounted(() => {
  5. hook();
  6. nextTick(() => {
  7. mounted = true;
  8. });
  9. });
  10. onActivated(() => {
  11. if (mounted) {
  12. hook();
  13. }
  14. });
  15. }