use-height.mjs 542 B

12345678910111213141516171819202122
  1. import { useRect } from "@vant/use";
  2. import { ref, onMounted, nextTick } from "vue";
  3. import { onPopupReopen } from "./on-popup-reopen.mjs";
  4. const useHeight = (element, withSafeArea) => {
  5. const height = ref();
  6. const setHeight = () => {
  7. height.value = useRect(element).height;
  8. };
  9. onMounted(() => {
  10. nextTick(setHeight);
  11. if (withSafeArea) {
  12. for (let i = 1; i <= 3; i++) {
  13. setTimeout(setHeight, 100 * i);
  14. }
  15. }
  16. });
  17. onPopupReopen(() => nextTick(setHeight));
  18. return height;
  19. };
  20. export {
  21. useHeight
  22. };