How to use the @vue/composition-api.onUnmounted function in @vue/composition-api

To help you get started, we’ve selected a few @vue/composition-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github logaretm / vue-use-web / src / LocalStorage.ts View on Github external
function handler(e: StorageEvent) {
    if (e.key === key) {
      value.value = e.newValue ? parseValue(e.newValue) : null;
    }
  }

  onMounted(() => {
    if (!initialized) {
      init();
    }

    window.addEventListener('storage', handler, true);
  });

  onUnmounted(() => {
    localStorage.setItem(key, JSON.stringify(value.value));
    window.removeEventListener('storage', handler);
  });

  return {
    value
  };
}
github logaretm / vue-use-web / src / Clipboard.ts View on Github external
export function useClipboard() {
  const text = ref('');

  async function onCopy() {
    text.value = await navigator.clipboard.readText();
  }

  onMounted(() => {
    window.addEventListener('copy', onCopy);
  });

  onUnmounted(() => {
    window.removeEventListener('copy', onCopy);
  });

  function write(txt: string) {
    text.value = txt;

    return navigator.clipboard.writeText(txt);
  }

  return {
    text,
    write
  };
}
github logaretm / vue-use-web / src / IntersectionObserver.ts View on Github external
isIntersecting.value = false;
    }, options);

    observe();
  });

  function unobserve() {
    if (!observer) return;

    if (target.value) {
      observer.unobserve(target.value);
    }
  }

  onUnmounted(unobserve);

  return {
    intersectionRatio,
    isIntersecting,
    isFullyInView,
    observe,
    unobserve
  };
}
github logaretm / vue-use-web / src / DeviceMotion.ts View on Github external
});

  function onDeviceMotion(event: DeviceMotionEvent) {
    acceleration.value = event.acceleration;
    accelerationIncludingGravity.value = event.accelerationIncludingGravity;
    rotationRate.value = event.rotationRate;
    interval.value = event.interval;
  }

  const handler = options.throttleMs ? throttle(options.throttleMs, onDeviceMotion) : onDeviceMotion;

  onMounted(() => {
    window.addEventListener('devicemotion', handler, false);
  });

  onUnmounted(() => {
    window.removeEventListener('devicemotion', handler, false);
  });

  return {
    acceleration,
    accelerationIncludingGravity,
    rotationRate,
    interval
  };
}
github pikax / vue-composable / dist / vue-composable.cjs.js View on Github external
function useEvent(el, name, listener, options) {
    const element = wrap(el);
    const remove = () => element.value.removeEventListener(name, listener);
    compositionApi.onMounted(() => element.value.addEventListener(name, listener, options));
    compositionApi.onUnmounted(remove);
    return remove;
}
github logaretm / vue-use-web / src / WindowScrollPosition.ts View on Github external
function setScrollPos() {
    x.value = window.pageXOffset;
    y.value = window.pageYOffset;
  }

  const onScroll = throttle(options.throttleMs, setScrollPos);

  onBeforeMount(() => {
    setScrollPos();
  });

  onMounted(() => {
    window.addEventListener('scroll', onScroll, { passive: true });
  });

  onUnmounted(() => {
    window.removeEventListener('scroll', onScroll);
  });

  return {
    x,
    y
  };
}
github logaretm / vue-use-web / src / Geolocation.ts View on Github external
});

  function updatePosition(position: Position) {
    locatedAt.value = position.timestamp;
    coords.value = position.coords;
    error.value = '';
  }

  let watcher: number;
  onMounted(() => {
    if ('geolocation' in navigator) {
      watcher = window.navigator.geolocation.watchPosition(updatePosition, undefined, options);
    }
  });

  onUnmounted(() => {
    if (watcher) {
      window.navigator.geolocation.clearWatch(watcher);
    }
  });

  return {
    coords,
    locatedAt,
    error
  };
}
github metaspace2020 / metaspace / metaspace / webapp / src / components / UppyUploader / index.tsx View on Github external
function preventDropEvents() {
  const preventDefault = (e: Event) => {
    e.preventDefault()
  }
  window.addEventListener('dragover', preventDefault, false)
  window.addEventListener('drop', preventDefault, false)

  onUnmounted(() => {
    window.removeEventListener('dragover', preventDefault)
    window.removeEventListener('drop', preventDefault)
  })
}